Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get android system default home app's name

Tags:

android

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)
like image 895
Crystal Jake Avatar asked Jan 13 '23 16:01

Crystal Jake


1 Answers

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)
like image 135
Prateek Avatar answered Jan 22 '23 13:01

Prateek