Send a broadcast from ADB to the phone: adb shell am broadcast -a com.android.test --es test_string "this is test string" --ei test_int 100 --ez test_boolean true
The following e represents the parameter extra,--es for extra is a string type,--ei represents the int type, and--ez represents the Boolean type.
Making your phone play and stop music is accomplished by broadcasting:
Let your phone play music:adb shell am broadcast -a com.android.music.musicservicecommand --es command "play"
Let your phone pause music:adb shell am broadcast -a com.android.music.musicservicecommand -es command "pause"
The corresponding Java code implementation:
Intent i = new Intent("com.android.music.musicservicecommand");i.putExtra("command", "pause");sendBroadcast(i);
Check whether your phone is playing music via ADB:adb shell dumpsys media.player
Since we only need to return part of the result, we can change it to:adb shell dumpsys media.player | grep ‘AudioTrack::dump‘ -A 4 | grep ‘state‘
The returned result will resemble the following paragraph:
AudioTrack::dump stream type(3), left - right volume(1.000000, 1.000000) format(16777216), channel count(2), frame count(262144) sample rate(44100), speed(1.000000), status(0) state(0), latency (6040)
which
State (0)-Playing
State (1)-Interrupted by popup
State (2)-paused/stopped
Reference Links:
- Https://stackoverflow.com/questions/25846015/how-to-get-media-player-state-using-adb-command
- Https://stackoverflow.com/questions/14910360/how-to-play-or-resume-music-of-another-music-player-from-my-code
Use the ADB command on your computer terminal to let your phone play music