我正在与媒体播放器和流式音频,我想知道什么是最好的方式来捕捉一个excpetion如果互联网或信号已关闭,无法再流式音频。如何捕捉异常,如果互联网或信号不佳
下面是我迄今为止所做的代码,因为您可以看到我将所有消息与相同的消息一起扔掉。
private class taskDoSomething extends AsyncTask<Void, Void, List<Employee>>
{
@Override
protected List<Employee> doInBackground(Void... params)
{
String url = "http://ofertaweb.ro/android/sleepandlovemusic/list_files.php";
try {
Get_Webpage obj = new Get_Webpage(url);
directory_listings = obj.get_webpage_source();
} catch (Exception e) {
Toast.makeText(this, "You have to be connected to the internet for this application to work", Toast.LENGTH_LONG).show();
finish();
}
}
这个问题将有助于连接测试 - > http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on- android-inetaddress-never-timeouts – Peter 2012-03-01 17:47:12