Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android O Replacement for getRunningServices

In previous versions of Android, I used this method to find if a service from another app was up and running. It worked reliably for me:

ActivityManager manager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List<RunningServiceInfo> services = manager.getRunningServices(Integer.MAX_VALUE);

However, with Android O, this is now deprecated and will only return information about the calling app's services. I've looked into other solutions, but I don't want to ask the user for more permissions, (UsageStatsManager, NotificationManager, etc).

Is there an alternate solution for obtaining if a service from a different app is running or not in Android O?

like image 510
JoeyG Avatar asked Aug 16 '17 14:08

JoeyG


1 Answers

It is intentional that there is no replacement for this function. It is not too clear from the documentation, but from the docs:

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

Basically, using the method to check other apps services was an unintended side-effect, so Google decided to remove it. Likely for privacy/security purposes to avoid apps "sniffing" other apps/services on the user's device.

You didn't mention your use-case, but you want to avoid asking users for permissions. However, Google is intentionally forcing developers to explicitly request permissions they need, a philosophy which you can find explained here.

like image 100
Sharp Avatar answered Nov 19 '22 03:11

Sharp