Crystal Jake
Crystal Jake

Reputation: 201

how to get android system default home app's name

If my phone is installed 3-4 home(launcher) apps,when I press home key,it will show a dialog to display the home apps that installed on my phone,then I will choose one as default.My question is: Can I get the default home app's package name through codes?

Solve it,use the follow api.

public abstract int getPreferredActivities (List<IntentFilter> outFilters, List<ComponentName> outActivities, String packageName)

Upvotes: 4

Views: 4999

Answers (3)

Prateek
Prateek

Reputation: 4013

Did you have a look at: PackageManager.resolveActivity(),

Intent intent= new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo defaultLauncher= getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
String nameOfLauncherPkg= defaultLauncher.activityInfo.packageName;

Make sure you use HOME intent as you will have the launcher on home, obviously.

Haven't used but you can try it with another flag i.e.

PackageManager.GET_INTENT_FILTERS in place of

PackageManager.MATCH_DEFAULT_ONLY

FINAL SOLUTION:

API packageManager,

public abstract int getPreferredActivities (List<IntentFilter> outFilters,List<ComponentName> outActivities, String packageName)

Upvotes: 10

Gal Rom
Gal Rom

Reputation: 6461

this is a method I use:

private String nameOfHomeApp()
    {
        try {
            Intent i = new Intent(Intent.ACTION_MAIN);
            i.addCategory(Intent.CATEGORY_HOME);
            PackageManager pm = getPackageManager();
            final ResolveInfo mInfo = pm.resolveActivity(i, PackageManager.MATCH_DEFAULT_ONLY);
            return mInfo.activityInfo.packageName;
        }
        catch(Exception e)
        {
            return "";
        }

    }

Upvotes: 0

Gal Rom
Gal Rom

Reputation: 6461

This is a method that return a String Array contains all the home apps on the device:

public String[] getDefaultLauncherList() {
    final Intent intent = new Intent(Intent.ACTION_MAIN); 
    intent.addCategory(Intent.CATEGORY_HOME); 
    final List<ResolveInfo> list = ((PackageManager)getPackageManager()).queryIntentActivities(intent, 0);      
    String[] toReturn=new String[list.size()];
    for(int i=0;i<list.size();i++)
        toReturn[i]=list.get(i).activityInfo.packageName;
    return toReturn;     
}

Upvotes: 0

Related Questions