Reputation: 23
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.
Upvotes: 0
Views: 96
Reputation: 1697
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());
Upvotes: 0
Reputation: 11
I think you have to implement the shouldOverrideUrlLoading()
method:
shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
Upvotes: 1