I created a webview app in android i need to implement the condition i.e. if the internet or wifi is available means it will proceed to open the weblink. If the internet or WIFI is not available means it will load into my HTML page which was present in the asset. How can we able to do it ?
package com.example.webview;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class Dadhboard<Bitmap> extends ActionBarActivity {
WebView web;
ProgressDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_dadhboard);
web = (WebView) findViewById(R.id.webview);
web.setWebViewClient(new WebViewClient() {
// This method will be triggered when the Page Started Loading
public void onPageStarted(WebView view, String url, android.graphics.Bitmap favicon) {
dialog = ProgressDialog.show(Dadhboard.this, null,
"Please Wait...Page is Loading...");
dialog.setCancelable(true);
super.onPageStarted(view, url, favicon);
}
public void onPageFinished(WebView view, String url)
{
dialog.dismiss();
super.onPageFinished(view, url);
}
// This method will be triggered when error page appear
public void onReceivedError(WebView view, int errorCode,String description, String failingUrl)
{
dialog.dismiss();
// You can redirect to your own page instead getting the default
// error page
Toast.makeText(Dadhboard.this,
"The Requested Page Does Not Exist", Toast.LENGTH_LONG).show();
web.loadUrl("http://www.google.com/");
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
web.loadUrl("http://www.google.com/");
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setUseWideViewPort(true);
}
}