Open Chrome App with URL

后端 未结 8 1450
情话喂你
情话喂你 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:24

    Here is a solution without a try catch, if chrome is installed, it will be used. Otherwise, it will go to the device default

    void open(Activity activity, String url) {
        Uri uri = Uri.parse("googlechrome://navigate?url=" + url);
        Intent i = new Intent(Intent.ACTION_VIEW, uri);
        if (i.resolveActivity(activity.getPackageManager()) == null) {
            i.setData(Uri.parse(url));
        }
        activity.startActivity(i);
    }
    

提交回复
热议问题