How to check if my application is the default launcher

DagW picture DagW · Nov 28, 2011 · Viewed 15k times · Source

I am developing a buissness-application that is essentially a Home-screen, and is supposed to be used as a Default Homescreen (being a "kiosk"-application).

Is there any way of checking if my Launcher is the default Launcher? Thanks!

Ps. Similar example, but for checking GPS-settings

LocationManager alm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
    Stuffs&Actions;
}

Answer

Sergey Glotov picture Sergey Glotov · Dec 2, 2011

You can get list of preferred activities from PackageManager. Use getPreferredActivities() method.

boolean isMyLauncherDefault() {
    final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);

    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    filters.add(filter);

    final String myPackageName = getPackageName();
    List<ComponentName> activities = new ArrayList<ComponentName>();
    final PackageManager packageManager = (PackageManager) getPackageManager();

    // You can use name of your package here as third argument
    packageManager.getPreferredActivities(filters, activities, null);

    for (ComponentName activity : activities) {
        if (myPackageName.equals(activity.getPackageName())) {
            return true;
        }
    }
    return false;
}