【问题标题】:Opening Other link in other browser android Webview在其他浏览器android Webview中打开其他链接
【发布时间】:2017-08-22 16:51:21
【问题描述】:

我在尝试覆盖 URL 时遇到问题 我在我的 webviewclient 中使用了这段代码

 mywebview.setWebViewClient(new WebViewClient(){

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (Uri.parse(url).getHost().contains("google") || Uri.parse(url).getHost().contains("goo.gl") ) {
                return false;
            }


            Intent  intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
            startActivity(intent);
            finish();
            return true ;
        }

    });    

然后包含上述字符串的链接在 webview 本身中打开,但其他链接(如 facebook)都无法在任何外部浏览器中打开,而 Youtube 链接正在 Youtube 应用程序中打开。 以及如何在 facebook 应用程序中打开 facebook 链接或在本地应用程序中打开市场链接。

【问题讨论】:

    标签: android webview android-webview


    【解决方案1】:

    我认为您需要的是 Chrome 自定义标签

    这里有一个提示创建一个。

    1.添加依赖

    dependencies {
        ...
        compile 'com.android.support:customtabs:23.4.0'
    }
    
    1. 创建并加载您的网址

    Uri uri = Uri.parse("https://example.com");

    CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
    
    // Begin customizing
    // set toolbar colors
    intentBuilder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
    intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
    
    // set start and exit animations
    intentBuilder.setStartAnimations(this, R.anim.slide_in_right, R.anim.slide_out_left);
    intentBuilder.setExitAnimations(this, android.R.anim.slide_in_left,
            android.R.anim.slide_out_right);
    
    // build custom tabs intent
    CustomTabsIntent customTabsIntent = intentBuilder.build();
    
    // launch the url
    customTabsIntent.launchUrl(activity, uri);
    

    请参阅Here 了解更多信息。

    【讨论】:

    • 不,我不想要自定义标签,我想要的是只在 webview 中打开一个特定网站,如果该网站有指向其他市场的链接,比如 playstore 链接,它应该直接打开 playstore
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    • 2021-09-11
    • 2018-08-24
    • 2015-05-10
    • 2011-07-26
    • 2015-12-09
    • 1970-01-01
    相关资源
    最近更新 更多