Issue
I'm trying to show an alert box instead of 'Web page not available' error page on my web view but not working even after adding onReceivedError() method as per documentation, please suggest me if I'm missing something, Here is my code...
public class CloudPageHolder extends Activity {
WebView mWebView;
ProgressDialog _dialog ;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.loadUrl("file:///android_asset/www/MyPage.html");
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
mWebView.getSettings().setPluginsEnabled(false);
mWebView.getSettings().setSupportMultipleWindows(false);
mWebView.getSettings().setSavePassword(false);
mWebView.getSettings().getAllowFileAccess();
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
new AlertDialog.Builder(CloudPageHolder.this)
.setMessage("Something went wrong!")
.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
})
.setCancelable(false)
.create()
.show();
}
});
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, final String message, final android.webkit.JsResult result)
{
new AlertDialog.Builder(CloudPageHolder.this)
.setMessage(message)
.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
result.confirm();
}
})
.setCancelable(false)
.create()
.show();
return true;
}
});
}
Thanks in Advance...
Solution
I am not sure of what your error is but the documentation of onReceivedError is somewhat missleading. At this point you CANNOT intercept HTTP error responses using this method. check these posts.
I am developing a similar workaround using the method described in this other post.
Will update with the details soon. Good luck!
Answered By - Romina Liuzzi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.