How to simulate hardware media control buttons on an Android emulator
Asked Answered
D

2

15

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!

Desiderate answered 10/6, 2013 at 22:50 Comment(0)
B
39

You can send keyevents using adb

   adb shell input keyevent <keycode>

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

Bicipital answered 10/6, 2013 at 23:28 Comment(1)
Note that 85 can also be "Play/Pause". That's the one I use all of the time so I don't have to track whether the media is playing or not.Woodall
E
2

There is another way to do this, from an Android application. You can call AudioManager.dispatchMediaKeyEvent(KeyEvent) and pass in the events with the necessary key code. Don't forget to call it twice, first with the event with ACTION_DOWN, then with ACTION_UP.

Epithalamium answered 23/12, 2017 at 21:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.