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?

Vardaan Sharma
  • 1,125
  • 1
  • 10
  • 21

1 Answers1

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)

Andrey Danilov
  • 6,194
  • 5
  • 32
  • 56