Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent WebView from displaying "web page not available"

Tags:

java

android

I have an app that makes extensive use of a WebView. When the user of this app does not have Internet connection, a page saying "web page not available" and various other text appears. Is there a way to not show this generic text in my WebView? I would like to provide my own error handling.

private final Activity activity = this;  private class MyWebViewClient extends WebViewClient  public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {   // I need to do something like this:   activity.webView.wipeOutThePage();   activity.myCustomErrorHandling();   Toast.makeText(activity, description, Toast.LENGTH_LONG).show();  } } 

I found out WebView->clearView doesn't actually clear the view.

like image 559
JoJo Avatar asked Jul 01 '11 18:07

JoJo


People also ask

What is alternative of WebView in android?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.

Is WebView slower than browser?

Web View is slower on both as compared to native android browser.

How can I make WebView keep a video or audio playing in the background?

I did something similar: Just extend WebView and override onWindowVisibilityChanged . This way, the audio continues to play if the screen is locked or another app is opened. However, there will be no controls in the notification bar or on the lockscreen.


1 Answers

First create your own error page in HTML and put it in your assets folder, Let's call it myerrorpage.html Then with onReceivedError:

mWebView.setWebViewClient(new WebViewClient() {     public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {         mWebView.loadUrl("file:///android_asset/myerrorpage.html");      } }); 
like image 148
SnowboardBruin Avatar answered Nov 15 '22 15:11

SnowboardBruin