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

AndroidAdb

Android Problem Overview


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.

Android Solutions


Solution 1 - Android

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

As explained in https://stackoverflow.com/questions/12157442/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 - Android

Try the command line

adb shell service list

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

Solution 3 - Android

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.

Solution 4 - Android

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.

Solution 5 - Android

For Android 10, list all currently running services:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndroDevView Question on Stackoverflow
Solution 1 - Androiduser276648View Answer on Stackoverflow
Solution 2 - AndroidDr. Ferrol BlackmonView Answer on Stackoverflow
Solution 3 - AndroidPaul RatazziView Answer on Stackoverflow
Solution 4 - AndroidGorvGoylView Answer on Stackoverflow
Solution 5 - AndroidJeff LuyetView Answer on Stackoverflow