使用URL打开Chrome应用 [英] Open Chrome App with URL
问题描述
是否可以通过默认的Android浏览器在Android上打开Chrome应用?我可以打开该应用程序,但无法将用户重定向到正确的页面.这是我尝试过的:
Is there a way to open Chrome app on Android from default Android browser? I'm able to open the app, but it doesn't redirect user to correct page. This is what I tried:
<a href="googlechrome://www.toovia.com">
我看到我可能必须形成一个意图URL,但是我希望有比这更简单的方法.
I saw that I may have to form an intent URL, but I was hoping that there is a much easier way than that.
这应该来自网页,并且不涉及网络视图.
This is supposed to be from a web page and there is no web view involved.
推荐答案
是的,但是如果未在系统上安装它,则会遇到ActivityNotFoundException.如果不可用,则应通过普通浏览器启动:
Yes, but if it's not installed on the system you'll run into an ActivityNotFoundException. If it's not available, you should launch through the normal browser:
String url = "http://mysuperwebsite";
try {
Intent i = new Intent("android.intent.action.MAIN");
i.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main"));
i.addCategory("android.intent.category.LAUNCHER");
i.setData(Uri.parse(url));
startActivity(i);
}
catch(ActivityNotFoundException e) {
// Chrome is not installed
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
}
这篇关于使用URL打开Chrome应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!