Android WebChrome Client Promts/Opens Link in browser rather than WebView
Android WebChrome Client Promts/Opens Link in browser rather than WebView
Upon launch of the activity, the webview should load the designated url but in the simulator it launches the native browser and on the physical device it prompts to open the url in in the browser.
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
WebView wv = findViewById(R.id.my_webview);
WebSettings webSettings = wv.getSettings();
wv.setWebChromeClient(new WebChromeClient());
webSettings.setJavaScriptEnabled(true);
wv.loadUrl("http://google.com");
Trying to get it so that the webview neither launches in native browser or prompts the user to open in browser. Also all embedded links should stay in the webview if clicked.
2 Answers
2
I think you have to implement the shouldOverrideUrlLoading()
method:
shouldOverrideUrlLoading()
shouldOverrideUrlLoading(WebView view, String url)
view.loadUrl(url);
return false;
This happens if you don't add a WebViewClient to your WebView instance. In order to enable navigation in the same WebView, you need to set a WebViewClient to your WebView instance wv. Add the following line:
wv.setWebViewClient(new WebViewClient());
Yes. Set both the clients.
– Venkata Narayana Malireddy
Sep 5 at 4:37
I'm assuming this solved your issue. Can you please mark the answer as accepted? If it hasn't, do let me know.
– Venkata Narayana Malireddy
Sep 8 at 15:58
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
So I add that line and also keep the line wv.setWebChromeClient(new WebChromeClient());
– theFizz
Sep 4 at 20:04