65

I want to know whether media player service (registers with media.player when device boots up) is running or not using adb shell. Is it possible?

I tried running ps command but no success.

1
  • if ps is not showing any information related to the media service, it means the process related to service is not started!(when device boots up)
    – sat
    Jun 5, 2012 at 11:44

5 Answers 5

100

As mentioned already, adb shell service list will only list system services.

As explained in Android Emulator: How can I get a list of services that are running, you can look for services created by apps by using

// List all services
adb shell dumpsys activity services

// List all services containing "myservice" in its name
adb shell dumpsys activity services myservice

If it returns something, it means the service is installed. To know if the service is currently started or stopped, look for app=ProcessRecord(...) or app=null respectively.

You can also do it Linux style with a simple

ps | grep myservice

while inside of your shell.

2
  • If my application is a system application, will be it be displayed with "adb shell service list" command?
    – savi
    Jan 4, 2017 at 18:57
  • "adb shell dumpsys activity services myservice" worked like a charm. Jun 20, 2017 at 19:30
82

Try the command line

adb shell service list

I get a list of service names and their package names as well.

3
  • media.player: [android.media.IMediaPlayerService] is among the listed services on my device. Jun 5, 2012 at 13:24
  • 53
    it seems it only shows the system service, rather than apps' service, right?
    – JackWM
    Feb 21, 2013 at 1:35
  • 1
    Can I kill them? the one of service list
    – Hugo
    May 20, 2013 at 11:21
28

To simply check whether a specific service is running, use:

adb shell service check <service>

For example, adb shell service check media.player gives Service media.player: found if it's running and Service media.player: not found otherwise.

If you need more detail, try dumpsys <service>. For example, adb shell dumpsys media.player returns information about media.player's clients, open files, etc.

Finally, if you really need serious detail for debugging, try adb shell dumpsys activity services which shows what's going on from ActivityManager's point of view. This includes information about intents, create times, last activity time, bindings, etc., etc. You can redirect the output if you want to store it for later viewing/searching. It's typically rather lengthy.

2
  • 2
    But knowing exact package name of your app's services could be cumbersome :( Can be used with | grep -i "myservice" Mar 5, 2015 at 19:26
  • adb shell service check <myservice> doesn't seem to return the same information as adb shell dumpsys activity services <myservice> and then looking at app=. I'm not sure which is wrong, but the first seemed to indicate a certain service wasn't running, while the latter did.
    – hBrent
    Jun 6, 2018 at 15:21
3

For Android 10, list all currently running services:

adb shell dumpsys activity services | grep "ServiceRecord" | awk '{print $4}' | sed 's/.$//' | sort
0

To know whether an app process is running or not (background or foreground):

adb shell pidof <package.name>

It'll return empty string if process is not running else its pid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.