2017-04-14 103 views
0

我正在開發Android Studio中的webview客戶端應用程序。 我有一個工作的splashscreen。當沒有互聯網連接時顯示另一個活動

我想檢查互聯網連接,或檢查網頁是否可用。 如果不是,則轉到除我的webview活動之外的其他活動。

回答

0

您可以使用自定義WebViewClient重寫onPageError方法並啓動該方法中的活動來執行簡單的操作。

class CustomWebViewClient extends WebViewClient(){ 
onReceivedError(WebView view, WebResourceRequest request, WebResourceError error){ 


startActivity(new Intent(this,Your_Second Activity.class)); 



    }} 

而設置的WebView客戶端一樣

webview.setWebViewClient(new CustomWebViewClient()); 
+0

如果這不作品嚐試此鏈接http://stackoverflow.com/questions/4238921/detect-whether-there-is-an-internet -connection,可供上的Android?RQ = 1 –

相關問題