0% found this document useful (0 votes)
17 views

Internet Display Error

This document checks internet connectivity and handles errors when loading a webview. It gets the active network from the ConnectivityManager, checks if it is WiFi or mobile data, and loads a URL in the webview. If there is no active connection, it hides the webview and starts a new activity. It also defines a webview client to start a new activity if an error is received when loading a page.

Uploaded by

SmartBee Studio
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Internet Display Error

This document checks internet connectivity and handles errors when loading a webview. It gets the active network from the ConnectivityManager, checks if it is WiFi or mobile data, and loads a URL in the webview. If there is no active connection, it hides the webview and starts a new activity. It also defines a webview client to start a new activity if an error is received when loading a page.

Uploaded by

SmartBee Studio
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Check ConnectivityManager

android.net.ConnectivityManager cm = (android.net.ConnectivityManager)
this.getSystemService(android.content.Context.CONNECTIVITY_SERVICE);

android.net.NetworkInfo activeNetwork = cm.getActiveNetworkInfo();

if (activeNetwork != null) {
if (activeNetwork.getType() == android.net.ConnectivityManager.TYPE_WIFI) {
webview1.setVisibility(View.VISIBLE);
webview1.loadUrl("http://thonkzoo.blogspot.com/?m=1");
} else if (activeNetwork.getType() == android.net.ConnectivityManager.TYPE_MOBILE)
{
webview1.setVisibility(View.VISIBLE);
webview1.loadUrl("http://thonkzoo.blogspot.com/?m=1");
}
} else {
webview1.setVisibility(View.GONE);
startActivity(new Intent(MainActivity.this, Page1Activity.class));
}

// Received Internet Error

webview1.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView


webview1, int errorCode, String description, String failingUrl) { //here you can do
something when received error in WebView

startActivity(new Intent(MainActivity.this, Page1Activity.class)); } });

// Intent Set Screen

startActivity(new Intent(Page1Activity.this, MainActivity.class));

You might also like