当没有互联网连接时显示另一个活动

问题描述:

我正在开发Android Studio中的webview客户端应用程序。 我有一个工作的splashscreen。当没有互联网连接时显示另一个活动

我想检查互联网连接,或检查网页是否可用。 如果不是,则转到除我的webview活动之外的其他活动。

您可以使用自定义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://*.com/questions/4238921/detect-whether-there-is-an-internet -connection,可供上的Android?RQ = 1 –