0

I have an app that open a link in a chrome custom tab. But when the user runs it for the first time(and he has multiple browsers installed), it gives the user a popup asking him to choose the default application (i.e do you wanna set UCBrowser as default, or chrome etc)

Is there someway I can skip this popup and always open in chrome for my app?

asked Apr 5, 2017 at 7:38
2
  • 1
    Just want to make sure you understand that Chrome might not be installed on the device. Commented Apr 5, 2017 at 8:52
  • 1
    we have an explicit check beforehand. If chrome is not installed we proceed in a web view. Commented Apr 5, 2017 at 9:59

1 Answer 1

3

Yes you can use PackageManager for this

String url = "http://www.example.com";
PackageManager pm = context.getPackageManager();
Intent launchIntent = pm.getLaunchIntentForPackage("com.android.chrome");
launchIntent.setData(Uri.parse(url));
if (launchIntent != null) {
 context.startActivity(launchIntent);
} else {
 Toast.makeText(context, "Chrome not found", Toast.LENGTH_SHORT).show();
}

Or you can just use setPackage method on Intent

Intent launchIntent = new Intent();
launchIntent.setAction("android.intent.action.VIEW");
launchIntent.addCategory("android.intent.category.BROWSABLE");
launchIntent.setPackage("com.android.chrome");
launchIntent.setData(Uri.parse(url));
startActivity(launchIntent);

but before setPackage you have to ensure that package exists (com.android.chrome in your case)

answered Apr 5, 2017 at 7:48
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.