Open Chrome App with URL

后端 未结 8 1446
情话喂你
情话喂你 2021-02-02 14:59

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:

<
8条回答
  •  梦谈多话
    2021-02-02 15:07

    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);
    }
    

提交回复
热议问题