Get a list of every launcher in Android

孤者浪人 提交于 2019-12-29 04:54:29

问题


In my application I want to show a list of every available launcher (for homescreen) on that specific Android phone. Is it possible to get some kind of information from Android OS and how do I make this call?

Thanks!

Kind regards Daniel


回答1:


You can query the list of ResolverInfo that match with a specific Intent. The next snippet of code print all installed launchers.

PackageManager pm = getPackageManager();
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> lst = pm.queryIntentActivities(i, 0);
for (ResolveInfo resolveInfo : lst) {
    Log.d("Test", "New Launcher Found: " + resolveInfo.activityInfo.packageName);
}



回答2:


Try the following:

  1. Obtain the list of installed applications:

    List pkgList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);

  2. Iterate over this list and obtain launcher activity using:

    getPackageManager().getLaunchIntentForPackage(packageName);

For details read here: PackageManager. Hope this helps.




回答3:


The code snippet above does NOT work accurately, as the result of launchers' list also includes system's setting's app whose package name is com.android.settings. This unexpected result happens on both my Pixel 2 (Android 8.0 ) and Nexus 6 (Android 7.1).



来源:https://stackoverflow.com/questions/6175821/get-a-list-of-every-launcher-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!