Which launcher is running?

Viewed 11382

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

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.

Related