我正在與媒體播放器和流式音頻,我想知道什麼是最好的方式來捕捉一個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