25

Is there any way to find out which browser is set as a default browser on android device? On android device there may be multiple browsers installed but out of which only one set as a default. I need to find it out programmatically.

Thanks in advance. Early response is appreciated..

kkarmalkar
  • 253
  • 1
  • 3
  • 5

2 Answers2

36

This code may help you:

Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://"));  
ResolveInfo resolveInfo = getPackageManager().resolveActivity(browserIntent,PackageManager.MATCH_DEFAULT_ONLY);

// This is the default browser's packageName
String packageName = resolveInfo.activityInfo.packageName;

and if wanna start it, do as follows:

startActivity(getPackageManager().getLaunchIntentForPackage(packageName));
lf215
  • 1,185
  • 7
  • 41
  • 83
exloong
  • 441
  • 3
  • 6
  • 3
    If you juste want the name of the app (like "Chrome"), use this : resolveInfo.loadLabel(getPackageManager()).toString(); – Hugo Gresse Dec 16 '14 at 15:29
  • 1
    this seems to be totally wrong based on http://stackoverflow.com/a/21257097/1168364 – lf215 Feb 16 '16 at 23:14
  • @exloong do you know how to go direct to the setting of that applications. – TheCoderGuy Mar 08 '19 at 14:47
  • 3
    For me (Android 9) this consistently returned `android` (the picker, I think), even when a default browser was properly selected. Changing the URI to a real URI (`http://example.com`) fixed it. – Tim Perry May 13 '20 at 17:36
  • 1
    @TimPerry Your solution also returned 'android' for android 7. any idea? please let me know. – Tushar Lathiya Feb 23 '22 at 09:23
  • 2
    If your app targets Android 11 or higher, you must add a declaration in the element in the manifest for this to work, as described here https://developer.android.com/training/package-visibility/use-cases – jake n May 19 '23 at 22:30
5

You are welcome to use PackageManager and resolveActivity() to attempt to determine what activity (in what app) will handle a particular Intent. However, this may indicate that the chooser will handle the request, because there is no current default (e.g., user just installed a new browser, and so the chooser will appear for the next Web browser request).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491