意图在网址中打开chrome - 而不是在棒棒糖中

时间:2015-06-18 19:02:26

标签: google-chrome android-intent

public void onClickApp(View view){
    Intent intent = new Intent("android.intent.action.MAIN");
    intent.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main"));
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.setData(Uri.parse("http://www.google.com"));
    startActivity(intent);
}

此代码打开Goog​​le Chrome并打开网站www.google.com。

在Android 5上,只能打开Goog​​le Chrome,但不能加载www.google.com。

为什么?

抱歉我的英语不好。

感谢

1 个答案:

答案 0 :(得分:0)

我认为那是因为android棒棒糖中不存在活动。 试试这个:

 public void onClickApp(View view){
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://www.google.com"));
    intent.setPackage("com.android.chrome");
    startActivity(intent);
}