I have an Android app which has a webview. When there\'s no internet connection, webview will display page not available. I want to make this look like an app as much as pos
You can check device is connect to internet through data or wifi by following code
ConnectivityManager manager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo i = manager.getActiveNetworkInfo();
boolean hasConnect = (i!= null && i.isConnected() && i.isAvailable());
if(hasConnect)
{
// show the webview
}
else
{
// do what ever you need when when no internet connection
}
After user go to webview , then if the connect is lost you can capture that event from following code
webView.setWebViewClient(new Callback());
public class Callback extends WebViewClient{
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
Toast.makeText(getApplicationContext(), "Failed loading app!, No Internet Connection found.", Toast.LENGTH_SHORT).show();
}
}
following permissions need to give