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());





So I add that line and also keep the line wv.setWebChromeClient(new WebChromeClient());
– theFizz
Sep 4 at 20:04





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)