I am using onReceivedError
with a custom error page to show when internet is not available in a WebView
. Below is the code I use for it. It doesn't work. It simply shows the webpage not available page when internet is not available.
Anyway the logcat shows me this error:
I/chromium﹕ [INFO:CONSOLE(0)] "Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png", source: data:text/html,chromewebdata (0)
my code is
private class myWebViewBrowser extends WebViewClient {
/*@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}*/
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
Log.e(String.valueOf(error.getErrorCode()), error.getDescription().toString());
view.loadUrl("file:///android_asset/error.html");
}
}
you can change
view.loadUrl(...);
to
view.loadDataWithBaseURL( "file:///android_asset/", html, "text/html","utf-8", null );
where
"file:///android_asset/" is your base url for load html
html is your html string
"text/html" is mime type for content
"utf-8" is encoding style
and last url as null, its for history reference.
This might be helpful :
https://groups.google.com/forum/#!topic/android-developers/4g6H0vr5_0E
Try Following Code :
private class myWebViewBrowser extends WebViewClient {
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
Log.e(String.valueOf(error.getErrorCode()), error.getDescription().toString());
view.loadDataWithBaseURL( "file:///android_asset/", html, "text/html","utf-8", null );
}
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
Log.e(String.valueOf(error.getErrorCode()), error.getDescription().toString());
view.loadDataWithBaseURL( "file:///android_asset/", html, "text/html","utf-8", null );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With