How to know whether service is running using adb shell in android

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.


Solution 1:

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.

Solution 2:

Try the command line

adb shell service list

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

Solution 3:

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.