How to simulate hardware media control buttons on an Android emulator

Tad*_*Tad 10 media android playback android-emulator android-hardware

Android supports hardware play/pause buttons on headsets and attached devices. I am trying to find a way to test support for those devices on an emulator. The Android documentation talks about how to add support for hardware playback controls, but, unfortunately, I can't find documentation of how to emulate them. Thanks!

msh*_*msh 22

您可以使用adb发送keyevents

   adb shell input keyevent <keycode>
Run Code Online (Sandbox Code Playgroud)

播放键码 - 126,暂停 - 85(参见KeyEvent)

  • 请注意,85 也可以是“播放/暂停”。这是我一直使用的,因此我不必跟踪媒体是否正在播放。 (2认同)