14

Usually there is one launcher on an Android device. But sometimes users install a few while only one of them is active.

How can I check which launcher is currently active on my Android device?

Thanks.

4 Answers 4

26

The home screen is started with the Intent ACTION_MAIN with category CATEGORY_HOME (from the javadoc for Intent). Use a ResolveInfo to this intent to know what application will start.

This will give you the default Home application:

final Intent intent = new Intent(Intent.ACTION_MAIN); 
intent.addCategory(Intent.CATEGORY_HOME); 
final ResolveInfo res = getPackageManager().resolveActivity(intent, 0); 
if (res.activityInfo == null) {
    // should not happen. A home is always installed, isn't it?
} else if ("android".equals(res.activityInfo.packageName)) {
    // No default selected     
} else {
     // res.activityInfo.packageName and res.activityInfo.name gives you the default app
} 

Now, if you want to know which one is running, it will take more time, because ActivityManager is slow:

// instead of the best, query all activities that match:
final List<ResolveInfo> list = ((PackageManager)getPackageManager()).queryIntentActivities(intent, 0);
// TODO from there, use ActivityManager to know which one is running and is in the list
1
  • 4
    Need to mention that if there is no default launcher and more than one installed, then you'll get something like com.android.internal.app.ResolverActivity. Dec 2, 2011 at 18:53
5
private String findLauncherPackageName(){       
    final Intent intent = new Intent(Intent.ACTION_MAIN); 
    intent.addCategory(Intent.CATEGORY_HOME); 
    final ResolveInfo res = getPackageManager().resolveActivity(intent, 0); 
    Log.e("ANDRO_ASYNC", String.format("findLauncherPackageName()%s",res.activityInfo.packageName));
    return res.activityInfo.packageName;
}
1
  • 2
    This code doesn't always return the active launcher, it will return the default launcher, if there is any.
    – THelper
    Oct 29, 2012 at 15:35
1

To improve upon previous answers, here is a self contained helper class you can use:

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

public class LauncherFinder {

    /**
     * Checks to see if the App currently set as the system launcher
     * matches the given package name.
     *
     * @param context
     * @param packageName
     * @return
     */
    public static boolean isPackageSetAsLauncher(Context context, String packageName) {
        String launcherPackageName = getLauncherPackageName(context);
        return packageName.equals(launcherPackageName);
    }

    /**
     * Get the package name of the app currently set as the system launcher
     * @param context
     * @return
     */
    public static String getLauncherPackageName(Context context) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);

        final PackageManager packageManager = context.getPackageManager();

        ResolveInfo result = packageManager.resolveActivity(intent, 0);

        if (result != null && result.activityInfo != null) {
            return result.activityInfo.packageName;
        }

        return null;
    }
}

and then use it like so:

boolean isLauncher = LauncherFinder.isPackageSetAsLauncher(getApplicationContext(), "com.package.name");

This will return true if com.package.name is currently set as the default launcher.

1
  • to improve on this answer add this method to check if own app is launcher: public static boolean isMyAppLauncherDefault(Context context) { final String myPackageName = context.getPackageName(); if (myPackageName.equals(getLauncherPackageName(context))) { return true; } return false; } Apr 23, 2023 at 16:20
0

you can check the title of active launcher only if it is marked default. otherwwise you will get result like

com.android.internal.app.ResolverActivity

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.