I'm testing the built-in WebView in the Android apps. My problem is that the following code
WebView webView = (WebView) findViewById(R.id.webView1);
webView.loadUrl("http://google.com");
triggers an intent (sugesting the installed browsers for opening the web) instead of open it in the built-in WebView. What should I do for avoiding that?
Android Permissionsxml file is necessary for an Activity to load a web page into a WebView.
If you want to override certain methods, you have to create a custom WebView class which extends WebView . Also, when you are inflating the WebView , make sure you are casting it to the correct type which is CustomWebView . CustomWebView webView = (CustomWebView) findViewById(R. id.
The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. It does not include any features of a fully developed web browser, such as navigation controls or an address bar. All that WebView does, by default, is show a web page.
Android System WebView is a system component for the Android operating system (OS) that enables Android apps to display web content directly inside an application.
WebView mWebView= (WebView) findViewById(R.id.webView1);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// Handle the error
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
mWebView.loadUrl("http://google.com");
This won't open other broweser. Have reference here from DEVELOPER's SITE.
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