获取 Android 中每个启动器的列表
在我的应用程序中,我想显示该特定 Android 手机上每个可用启动器(用于主屏幕)的列表。是否可以从 Android 操作系统获取某种信息以及如何进行此调用?
谢谢!
亲切的问候 丹尼尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以查询与特定Intent匹配的ResolverInfo列表。下一个代码片段打印所有已安装的启动器。
You can query the list of ResolverInfo that match with a specific Intent. The next snippet of code print all installed launchers.
上面的代码片段不能准确工作,因为启动器列表还包括系统设置的应用程序,其包名为 com.android.settings。我的 Pixel 2 (Android 8.0) 和 Nexus 6 (Android 7.1) 上都会出现这种意外结果。
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).
请尝试以下操作:
获取已安装应用程序的列表:
List pkgList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
迭代此列表并使用以下方法获取启动器活动:
getPackageManager().getLaunchIntentForPackage(packageName);
有关详细信息,请阅读此处:PackageManager。希望这有帮助。
Try the following:
Obtain the list of installed applications:
List pkgList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
Iterate over this list and obtain launcher activity using:
getPackageManager().getLaunchIntentForPackage(packageName);
For details read here: PackageManager. Hope this helps.