get the current Launcher's Package Name - Android App

Android examples for App:Package

Description

get the current Launcher's Package Name

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.Intent;

import android.content.pm.ResolveInfo;

public class Main {
    /**/*from   w  w w .  ja  va  2 s  . com*/
     * get the current Launcher's Package Name
     */
    public static String getCurrentLauncherPackageName(Context context) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        ResolveInfo res = context.getPackageManager().resolveActivity(
                intent, 0);
        if (res == null || res.activityInfo == null) {
            // should not happen. A home is always installed, isn't it?
            return "";
        }
        if (res.activityInfo.packageName.equals("android")) {
            return "";
        } else {
            return res.activityInfo.packageName;
        }
    }
}

Related Tutorials