How to simulate hardware media control buttons on an Android emulator

别说谁变了你拦得住时间么 提交于 2019-12-05 16:47:09

问题


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!


回答1:


You can send keyevents using adb

   adb shell input keyevent <keycode>

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




回答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.



来源:https://stackoverflow.com/questions/17034050/how-to-simulate-hardware-media-control-buttons-on-an-android-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!