如何在android浏览器中默认打开Chrome浏览器中的网页

时间:2014-12-24 09:47:39

标签: android

我尝试在Chrome中默认打开我的网页,我该怎么办呢。 MyCode是:

       try {
            Intent i = new Intent("android.intent.action.VIEW");
            i.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.example.webviewdemo.MainActivity"));
            i.addCategory("android.intent.category.LAUNCHER");
            i.setData(Uri.parse(url));
            startActivity(i);
        }
        catch(ActivityNotFoundException e)
        {
             //exception raised
            e.printStackTrace();
            // Chrome is probably not installed
        }

当我运行此活动时未找到异常显示错误

1 个答案:

答案 0 :(得分:0)

试试这个,

internetIntent.setComponent(new ComponentName("com.android.chrome","com.android.browser.BrowserActivity"));
internetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);