Android 中是否有任何方法可以强制打开要在 Chrome 中打开的链接? [英] Is there any way in Android to force open a link to open in Chrome?

查看:32
本文介绍了Android 中是否有任何方法可以强制打开要在 Chrome 中打开的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在测试使用大量 jQuery 动画开发的 Web 应用程序,我们注意到内置 Web 浏览器的性能非常差.在 Chrome 中进行测试时,Web 应用程序的性能快得令人难以置信.我只是想知道是否有任何类型的脚本可以在 Android 版 Chrome 中强制打开链接,类似于在 iOS 中的做法.

I'm currently testing a web app developed with lots of jQuery animations, and we've noticed really poor performance with the built-in web browser. While testing in Chrome, the performance of the web app is unbelievably quicker. I'm just wondering if there was any type of script that would force open a link in Chrome for Android, similar to how it's done in iOS.

推荐答案

实现此目的的更优雅的方法是照常使用 Intent.ACTION_VIEW 意图,但添加包 com.android.chrome 到意图.这与 Chrome 是否为默认浏览器无关,并确保行为与用户从选择器列表中选择 Chrome 完全相同.

A more elegant way to achieve this is to use the Intent.ACTION_VIEW intent as normal, but add the package com.android.chrome to the intent. This works regardless of whether Chrome is the default browser and ensures exactly the same behavior as if the user had selected Chrome from the chooser list.

String urlString = "http://mysuperwebsite";
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(urlString));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.android.chrome");
try {
    context.startActivity(intent);
} catch (ActivityNotFoundException ex) {
    // Chrome browser presumably not installed so allow user to choose instead
    intent.setPackage(null);
    context.startActivity(intent);
}


更新

对于 Kindle 设备:

以防万一您想打开亚马逊默认浏览器,以防亚马逊 Kindle 中未安装 Chrome 应用程序


Update

For Kindle Devices:

Just in case if you want to open Amazon Default Browser in case chrome app is not installed in Amazon Kindle

String urlString = "http://mysuperwebsite";
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(urlString));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.android.chrome");
try {
    context.startActivity(intent);
} catch (ActivityNotFoundException ex) {
    // Chrome browser presumably not installed and open Kindle Browser
    intent.setPackage("com.amazon.cloud9");
    context.startActivity(intent);
}

这篇关于Android 中是否有任何方法可以强制打开要在 Chrome 中打开的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆