44

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?

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
JoeyG
  • 611
  • 6
  • 14
  • 6
    I doubt it. Google specifically *wants* the user to know that you have access to this sort of information (via other permissions), if you have access to it at all. – CommonsWare Aug 16 '17 at 14:20
  • That's what I am afraid of. It seems Android is locking down this type of interaction, making apps much more siloed (without user consent). Which is good for users, but not fun for developers. – JoeyG Aug 16 '17 at 15:00
  • It's a specific use case I'm looking for that I need this functionality. I don't need the service to be running, but need to know if it is running. – JoeyG Aug 17 '17 at 17:02
  • One can use it for automated tests. – Paul Omta Nov 24 '17 at 12:27
  • Is there any find a solution for above? please help me – Makvin Jul 25 '18 at 09:42
  • Both of those questions were asked after I asked this question so they are duplicates of my question. – JoeyG Apr 01 '19 at 13:46

2 Answers2

1

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.

Sharp
  • 1,335
  • 1
  • 12
  • 27
  • Thanks for your comment, however, after almost 3 years since the original question was posted I think it is safe to say that at the time there was no alternative and there has not been one introduced since. – JoeyG Aug 03 '20 at 15:40
  • Which is why I left a comment so anyone looking for an answer isn't left hanging.. – Sharp Aug 03 '20 at 18:43
0

As per documentation:

As of O, this method is no longer available to third party applications.
For backwards compatibility, it will still return the caller's own services.

But may be this solution will help: How to check if a service is running on Android?

Peter Staranchuk
  • 1,343
  • 3
  • 14
  • 29
  • Thanks, yes I read the documentation and that is why I was specifically asking for a replacement. As the question also states it must return a status for services from different apps, so creating a static variable as the linked solution suggests will not work. – JoeyG Aug 13 '19 at 00:14