【问题标题】:WebView not launching chrome for external linksWebView 没有为外部链接启动 chrome
【发布时间】:2015-12-22 00:00:27
【问题描述】:

我正在创建一个加载网站的网络应用程序。我希望网站上的所有页面都加载到 WebView 中,但任何其他链接(Google+、Amazon 等)都可以触发 Chrome 或浏览器。

我尝试了 setWebViewClient() 的不同变体,但它会不断加载 WebView 中的所有页面,包括 Google plus 和 Amazon。

我的代码:

WebView myWebView = (WebView) findViewById(R.id.web);
myWebView.loadUrl("my.site");
myWebView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.equals("http://my.site"))
            view.loadUrl(url);
        else
            return false;
        return true;
    }
});

我做错了什么? 我是否需要在“其他”部分中有一个意图?如果是这样,我该怎么做?意图.putExtra(url);设置要在网络浏览器中加载的网址会引发错误。

【问题讨论】:

    标签: android google-chrome android-intent webview webviewclient


    【解决方案1】:

    改变

    if (url.equals("http://my.site"))
    

    if (url.startsWith("http://my.site"))
    

    String url参数是完整的URL,有directory/page#anchor?query等。

    【讨论】:

      猜你喜欢
      • 2013-07-05
      • 2011-02-01
      • 2023-03-22
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多