WebView clicks opens mobile browser

北城余情 提交于 2019-12-13 18:16:17

问题


There is a WebView which loads mobile-optimized URL (webpage). But when I click on a link, it does not load inside of the WebView (inside of the app), but mobile browser opens.

How to prevent this?

I tried overloading URLs via shouldOverrideUrlLoading(), but it did not help.

This is a code.

webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setPluginsEnabled(true);
if (Build.VERSION.SDK_INT > 7) {
    webSettings.setPluginState(WebSettings.PluginState.ON);
}
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.equals(url)) {
            view.loadUrl(url);
            return true;
        }
        return false;
    }


    @Override
    public void onLoadResource(WebView view, String url) {
    }
});
webView.loadUrl("http://some-url.com");

EDIT

Does GET or POST posting methods have anything with links' clicks open mobile web browser???


回答1:


Return true instead of false in shouldOverrideUrlLoading.

From the documentation:

shouldOverrideUrlLoading returns True if the host application wants to leave the current WebView and handle the url itself, otherwise return false.



来源:https://stackoverflow.com/questions/7263367/webview-clicks-opens-mobile-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!