9

In my application I want to show a list of every available launcher (for homescreen) on that specific Android phone. Is it possible to get some kind of information from Android OS and how do I make this call?

Thanks!

Kind regards Daniel

Daniel Nord
  • 535
  • 5
  • 10

3 Answers3

20

You can query the list of ResolverInfo that match with a specific Intent. The next snippet of code print all installed launchers.

PackageManager pm = getPackageManager();
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> lst = pm.queryIntentActivities(i, 0);
for (ResolveInfo resolveInfo : lst) {
    Log.d("Test", "New Launcher Found: " + resolveInfo.activityInfo.packageName);
}
Fede
  • 935
  • 8
  • 14
  • 1
    **1.** you should check `(!lst.isEmpty())`, see [off. reference](http://developer.android.com/reference/android/content/pm/PackageManager.html). **2.** Your answer is better then @Flavio's, see comments – Alexander Malakhov Aug 14 '13 at 03:44
  • Also use `Intent.ACTION_MAIN` for **Intent action** and `Intent.CATEGORY_HOME` for **Intent category** instead of hard coded Strings. – electrocrat Jun 04 '15 at 05:02
  • 1
    the isEmpty() check is useless here in a for each – JacksOnF1re Jun 18 '15 at 09:43
  • Thanks @electrocrat and JacksOnF1re for the suggestions. Answer edited. – Fede Jul 03 '15 at 07:28
2

The code snippet above does NOT work accurately, as the result of launchers' list also includes system's setting's app whose package name is com.android.settings. This unexpected result happens on both my Pixel 2 (Android 8.0 ) and Nexus 6 (Android 7.1).

somard
  • 51
  • 4
0

Try the following:

  1. Obtain the list of installed applications:

    List pkgList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);

  2. Iterate over this list and obtain launcher activity using:

    getPackageManager().getLaunchIntentForPackage(packageName);

For details read here: PackageManager. Hope this helps.

Flavio
  • 6,205
  • 4
  • 30
  • 28
  • 1
    IIUC, `getLaunchIntentForPackage(..)` will return you launch Intent for any app, not just Launcher. E.g. "Settings" and "Media Player" apps have launch intents as well – Alexander Malakhov Aug 09 '13 at 07:43