Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android webview launches browser when calling loadurl

I created an Activity that has a title and a web view in a LinearLayout. In the onResume() method it calls webView.loadUrl(url). The problem is that the activity first shows the title with the rest of the screen blank, then the device browser is launched with the page for the URL. What I want to see is the page being shown in the WebView below the title. What could be the problem?

Edit: Ok, did some further search and found this one:

Clicking URLs opens default browser

It points to the WebView tutorial here.

Just implement the web client and set it.

like image 705
Ray Avatar asked Oct 12 '11 20:10

Ray


People also ask

Is Android WebView deprecated?

The Android system webview custom cache file has been deprecated and removed in Android 13. New apps and any app updates will now use the operating system default cache location.

How can I improve my WebView performance?

I read about how to increase performance of WebView by implementing Caching web resources like JS, CSS and image files. You can also static resources in your native application, and by intercepting the Resource requests you can override the default behaviour of WebView.

How do I enable JavaScript on Android WebView?

Enable JavaScript JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView . You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.

What browser is used in WebView?

On Android 7.0, 8.0 and 9.0, Google Chrome handles the embedded browsing functions. On other Android OS versions, web app performance may suffer without WebView enabled.


2 Answers

Answering my question based on the suggestions from Maudicus and Hit.

Check the WebView tutorial here. Just implement the web client and set it before loadUrl. The simplest way is:

myWebView.setWebViewClient(new WebViewClient()); 

For more advanced processing for the web content, consider the ChromeClient.

like image 152
Ray Avatar answered Oct 11 '22 11:10

Ray


Use this:

lWebView.setWebViewClient(new WebViewClient()); 
like image 32
oops.objective Avatar answered Oct 11 '22 12:10

oops.objective