Created
February 26, 2017 13:01
-
-
Save Ray33/7ce134b68159a9ad6a7b773b9a4da55f to your computer and use it in GitHub Desktop.
Get browser package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getBrowserPackage(Intent intent, Context context){ | |
PackageManager pm = context.getPackageManager(); | |
List<ResolveInfo> appsList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); | |
String tmpPkg = "", pkg=""; | |
for (ResolveInfo app : appsList){ | |
tmpPkg = app.activityInfo.packageName.toLowerCase(); | |
if ("com.android.chrome".equals(tmpPkg)){ | |
return tmpPkg; | |
} | |
if (tmpPkg.contains("browse") || tmpPkg.contains("chrome") || tmpPkg.contains("com.UCMobile.intl") || tmpPkg.contains("org.mozilla.firefox") || tmpPkg.contains("com.opera.mini.native")){ | |
pkg = tmpPkg; | |
} | |
} | |
return pkg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(SOME_URL));
final String browserPackage = ActivityUtils.getBrowserPackage(intent, context);
if (!browserPackage.isEmpty()) {
intent.setPackage(browserPackage);
} else {
intent.setPackage(null);
}
startActivity(intent);