How to list all services in an android device

做~自己de王妃 提交于 2019-12-02 07:13:42

问题


I am looking for a reliable way to programmatically find and list all available services in an Android device (both running and not running).

The closest thing I could find in the API is getRunningServices() on ActivityManager but even that is marked boldly:

Note: this method is only intended for debugging or implementing service management type user interfaces.

and it lists only running services anyway.

Is there a reliable way to find all available services in a given Android device?

(ideally, if such method exist, should be compatible with API/SDK 8 and up)


回答1:


You can enumerate all packages and retrieve their services:

List<PackageInfo> pkgs = getPackageManager().getInstalledPackages(PackageManager.GET_SERVICES);
for(PackageInfo pkg : pkgs) {
  // You can now use pkg.services
}

Compatible to API 1.



来源:https://stackoverflow.com/questions/19758611/how-to-list-all-services-in-an-android-device

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