siralam/WebViewSuite

how to use onReceivedError

LOG-TAG opened this issue · 1 comments

I just want know how can get onReceivedError

mWebView.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return false;
			}
			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				super.onPageStarted(view, url, favicon);
				if (prgs.getVisibility() == View.GONE) {
					prgs.setVisibility(View.VISIBLE);
				}
			}

			@Override
			public void onLoadResource(WebView view, String url) {
				super.onLoadResource(view, url);
			}

			@Override
			public void onPageFinished(WebView view, String url) {
				super.onPageFinished(view, url);

				if (prgs.getVisibility() == View.VISIBLE)
					prgs.setVisibility(View.GONE);

				// check if splash is still there, get it away!
				if (splash.getVisibility() == View.VISIBLE)
					splash.setVisibility(View.GONE);
				// slideToBottom(splash);

			}
			public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {


                if (failingUrl.startsWith("tel:") || failingUrl.startsWith("sms:") || failingUrl.startsWith("smsto:") || failingUrl.startsWith("mms:") || failingUrl.startsWith("mmsto:"))
            {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(failingUrl));
                startActivity(intent);
                //return true;
            }else{
                    mWebView.loadUrl("file:///android_asset/error.html");
                }
           // return false;


			}






		});

when internet not available show other html file or native error page using onReceivedHttpError or anyother error handling via webviewclient!

I tried this it's not working

		webViewSuite.customizeClient(new WebViewSuite.WebViewSuiteCallback() {
			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				//Do your own stuffs. These will be executed after default onPageStarted().
			}

			@Override
			public void onPageFinished(WebView view, String url) {
				//Do your own stuffs. These will be executed after default onPageFinished().
			}

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {

				if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url.startsWith("mms:") || url.startsWith("mmsto:"))
            {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                return true;
            }
            return false;
				//Override those URLs you need and return true.
				//Return false if you don't need to override that URL.
			}

			public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceError error){
				webViewSuite.startLoadData("file:///android_asset/error.html","text/html", "utf-8" );
			}

//			
//			}

		});

I tried with following setWebViewClient but progressbar didn't hide after content loaded to 100%!!

        webView.setWebViewClient(new WebViewClient() {

                   @Override
                   public boolean shouldOverrideUrlLoading(WebView view, String url) {
                       view.loadUrl(url);
                       return false;
                   }

                   @Override
                   public void onPageStarted(WebView view, String url, Bitmap favicon) {
                       super.onPageStarted(view, url, favicon);
//
                   }

                   @Override
                   public void onLoadResource(WebView view, String url) {
                       super.onLoadResource(view, url);
                   }

                   @Override
                   public void onPageFinished(WebView view, String url) {
                       super.onPageFinished(view, url);



                   }
                   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {



                     //  webView.loadUrl("file:///android_asset/error.html");
   				//	webViewSuite.startLoadData("file:///android_asset/error.html","text/html", "utf-8" );

   					webViewSuite.startLoading("file:///android_asset/error.html");

                   }






               });

your last method should work, just use webViewSuite.toggleProgressBar(false) in onReceivedError.