问题
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