Android WebView NOT launching new browser

柔情痞子 提交于 2019-12-23 22:19:14

问题


Previously when using a webview in android, clicking any link would force the "proper" browser to open and then web browsing would continue in that instance.

However this seems to no longer be the case. The following code results in all links staying inside the webview, but I actually want the links to launch a new browser instance. Did this change in 2.3 ?

Note I am asking the opposite of what most people ask (they ask how to keep all links inside the webview, I want them to launch outside)

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        WebView view = new WebView(this);
        setContentView(view);

        view.loadUrl("http://news.bbc.co.uk");

    }
}

EDIT: Clarification - the first URL will load in the WebView and all subsequent clicks will open in a new browser. This is simplification from what I really want, but good enough.

Bascially the problem is, previously clicking a link would open a new browser session. Most people don't want that (hence the questions on here about it) but I do. However for some reason now it seems to load in the webview all the time (2.3 perhaps?)


回答1:


Let me understand. Do you want to launch the first webpage in the same webview, while the other hyperlinks to go to the default browser, or you want the default browser itself to open for the first link clicked?

If it's the first case, I don't exactly know, unless you know some way to gather the link URL from the webview.

For the second instance, i.e. launching the default browser for any URL click, just skip (remove) this line: view.setWebViewClient(new WebViewClient() { });, which will open all the links in the default browser, and not the webview itself.




回答2:


Houps, wrong answer, I misunderstood your question. Need to delete...



来源:https://stackoverflow.com/questions/7384384/android-webview-not-launching-new-browser

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