Reputation: 1307
I'm trying to display an image which is present in my server, through WebView
of Android
. Occasionally I'm getting page not available error in WebView
. But able to access the page in alternate try. Unable to figure out the reason, though server is up and able to access same image through regular browser.
Internet permission is defined in android-manifest
file..
Trying to access image this way:
webView.loadUrl("http://xxx.xxx.xx.xx/ql/PDLAgreementTemplate/PDL_AG2.jpg");
Please let me know how I can overcome this. Is there any option to reload the page without user interaction when that error occurs?
Upvotes: 1
Views: 147
Reputation: 296
If there's any error when loading a webpage in the WebView, the method "onReceivedError" will be called. You can reload the page in this method. This method is inherited from the WebViewClient class:
private class HelloWebViewClient extends WebViewClient {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
view.reload();
}
}
So you have to create the client and set it in your webview:
webview.setWebViewClient(new HelloWebViewClient());
Upvotes: 1