How to simulate media control buttons on an Android emulator

Android supports hardware play / pause buttons on headsets and connected devices. I am trying to find a way to test support for these devices on an emulator. The Android documentation talks about how to add support for hardware playback controls, but unfortunately, I cannot find documentation on how to simulate them. Thanks!

+7
source share
2 answers

You can send key events using adb

adb shell input keyevent <keycode> 

keycode for playback - 126, pause - 85 (see KeyEvent )

+15
source

There is another way to do this from an Android app. You can call AudioManager.dispatchMediaKeyEvent(KeyEvent) and pass events using key code. Remember to call it twice, first with an event with ACTION_DOWN , then with ACTION_UP .

0
source

All Articles