Volume Control in android application

后端 未结 4 1825
既然无缘
既然无缘 2020-11-27 02:29

I\'d like to know how to control my application\'s volume from the volume keys (contrary to my belief , I\'ve read they control only the ringer volume). Should I overwrite t

4条回答
  •  难免孤独
    2020-11-27 02:58

    There was another question from a long time ago that asked the same thing. Essentially the answer is: don't override the onKeyDown and onKeyUp buttons. It's much better to simply use this one line setVolumeControlStream(AudioManager.STREAM_MUSIC); in your onCreate() method. That tells the OS that the volume buttons should affect the "media" volume when your application is visible, and that's the volume it uses for your application.

    As for controlling the Media volume no matter what app is visible, I'm not sure that can be done - or if it could, whether that would be a good thing.

提交回复
热议问题