Why Url In Not Loading In My Application With Webview
whey i wrote below code, the url is opening in the default browser, why its not loading in the my app. setContentView(R.layout.activity_main); myWebView = (WebView) findViewById(R.
Solution 1:
Try setting a WebViewClient
on the WebView
:
myWebView.setWebViewClient(newWebViewClient() {
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
returntrue;
}
});
myWebView.loadUrl("http://www.google.com");
Solution 2:
Maybe you want this solution:
WebViewwebview= findViewById(R.id.webviewLW);
webview = newWebView(this);
webview.getSettings().setLoadsImagesAutomatically(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webviewLWComplience.setWebViewClient(newWebViewClient() {
@SuppressWarnings("deprecation")@OverridepublicvoidonReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(MainActivity.this, description, Toast.LENGTH_SHORT).show();
}
@TargetApi(android.os.Build.VERSION_CODES.M)@OverridepublicvoidonReceivedError(WebView view, WebResourceRequest req, WebResourceError rerr) {
// Redirect to deprecated method, so you can use it in all SDK versions
onReceivedError(view, rerr.getErrorCode(), rerr.getDescription().toString(), req.getUrl().toString());
}
});
webviewLWComplience.loadUrl(CONSTANTS.HOST_URL);
setContentView(webviewLWComplience);
Don't forget to add permission:
<uses-permissionandroid:name="android.permission.INTERNET"/>
Also check this link: https://stackoverflow.com/a/7306176
Post a Comment for "Why Url In Not Loading In My Application With Webview"