16

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
  • 9,239
  • 7
  • 57
  • 79
Nishant Virmani
  • 215
  • 1
  • 2
  • 10

5 Answers5

30

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
  • 30,049
  • 21
  • 112
  • 147
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,261
  • 15
  • 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
  • 544
  • 1
  • 9
  • 24
1

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:

<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.

For guidance on how to call on the PackageManager.resolveActivity(intent:flags:), PackageManager.queryIntentActivities(intent:flags:) etc methods, see the other answers in this thread.

Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
1

You can get it like this:

val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_HOME)
val resolveInfo: ResolveInfo = context.packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)?: return null
val currentLauncherPackageName: String = resolveInfo.activityInfo.packageName
val currentLauncherClassName: String = resolveInfo.activityInfo.name

Two boundary cases:

Result 1: android (This happens when the system has multiple launcher applications, but the user does not make the default selection)

Result 2: The corresponding package name.

BAByte
  • 11
  • 2