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?
-
1Just want to make sure you understand that Chrome might not be installed on the device.Vladyslav Matviienko– Vladyslav Matviienko2017年04月05日 08:52:09 +00:00Commented Apr 5, 2017 at 8:52
-
1we have an explicit check beforehand. If chrome is not installed we proceed in a web view.Vardaan Sharma– Vardaan Sharma2017年04月05日 09:59:47 +00:00Commented Apr 5, 2017 at 9:59
1 Answer 1
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)
Comments
Explore related questions
See similar questions with these tags.