13

I want to get the package name of the current launcher that I have currently installed. I tried using the link http://stackoverflow.com/questions/10344824/how-can-i-get-the-package-name-of-the-current-launcher-in-android-2-3-and-above

but it gives the result as "android". I want the complete launcher name .

List Of Launchers

I want the list of launchers installed and the current launcher selected

Thanks in advance

Xavi Montero
  • 7,777
  • 3
  • 47
  • 72
Nishant Virmani
  • 185
  • 1
  • 1
  • 10

4 Answers4

28

you can get current launcher package name using below code:

PackageManager localPackageManager = getPackageManager();
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
String str = localPackageManager
        .resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)
        .activityInfo
        .packageName;
Log.e("Current launcher Package Name:", str);
Adil Hussain
  • 27,407
  • 21
  • 100
  • 139
Ravi Kant
  • 820
  • 6
  • 13
2

as Fede's answer in Get a list of every launcher in Android

get a list of all installed launchers.

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> lst = getPackageManager().queryIntentActivities(intent, 0);
if (!lst.isEmpty()) {
   for (ResolveInfo resolveInfo : lst) {
        Log.d("Test", "New Launcher Found: " + resolveInfo.activityInfo.packageName);
   }
}
Community
  • 1
  • 1
wrkwrk
  • 2,153
  • 14
  • 21
  • This does not ensure that the first result is the one currently in use (as the question specifically requests) and actually makes no attempt to determine the one in use at all. – Abandoned Cart Jun 14 '19 at 23:41
2

Following code works perfectly to get the current launcher app package name.

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
String currentLauncherName= resolveInfo.activityInfo.packageName;
Log.d("Current Launcher: ", currentLauncherName);
Jayavinoth
  • 494
  • 1
  • 9
  • 21
0

With the package visibility changes introduced in Android 11, it is now necessary to add a queries element in your application's manifest file as below before you can query one of the PackageManager.resolveActivity(intent:flags:), PackageManager.queryIntentActivities(intent:flags:) etc methods for the home (a.k.a. launcher) activities that are installed on the device as described in the other answers in this thread:

<queries>
    <intent>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.HOME" />
    </intent>
</queries>

If this queries element is omitted from your application's manifest, then the device will report the com.android.settings.FallbackHome activity as the one and only home activity installed on the device.

Adil Hussain
  • 27,407
  • 21
  • 100
  • 139