How to get the default Android app name for Android

If 3-4 home (start-up) applications are installed on my phone, when I press the home key, it will display a dialog box for displaying home applications installed on my phone, after which I will select it by default. My question is: Can I get the default home application package name through codes?

Decide use the following api.

public abstract int getPreferredActivities (List<IntentFilter> outFilters, List<ComponentName> outActivities, String packageName) 
+4
source share
3 answers

You looked 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 the HOME intent, as you will of course have a launcher at home.

Not used, but you can try it with a different flag, i.e.

PackageManager.GET_INTENT_FILTERS instead

 PackageManager.MATCH_DEFAULT_ONLY 

FINAL DECISION:

PackageManager API,

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

This is a method that returns a String Array that contains all the home applications 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; } 
0
source

this is the 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 ""; } } 
0
source

All Articles