Skip to content Skip to sidebar Skip to footer

No Internet Message Webview Fragment With Pull Do To Refresh

I searched here about 'no internet message' for a webview, and i tried some codes, but no sucess. I have one WebView in fragment and i want to check if the device have internet or

Solution 1:

In my case I use AlertDialogBox To show Internet Error and On try again button check Internet connection

 @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            //Clearing the WebView
            try {
                webView.stopLoading();
            } catch (Exception e) {
            }
            try {
                webView.clearView();
            } catch (Exception e) {
            }
            if (webView.canGoBack()) {
                webView.goBack();
            }
            webView.loadUrl("about:blank");
            AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
            alertDialog.setTitle("Error");
            alertDialog.setMessage("Check your internet connection and try again.");
            alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Try Again", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                    startActivity(getIntent());
                }
            });
            alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    finish();
                }
            });
            alertDialog.setCancelable(false);
            alertDialog.show();
            super.onReceivedError(webView, errorCode, description, failingUrl);


        }

Post a Comment for "No Internet Message Webview Fragment With Pull Do To Refresh"