2

I play a song in background, and the screen is off now. I press the volume key, the volume of the music stream changes. How can it happen? I have searched for a long time for a solution about how to detect the volume keys press event when screen off, but I don't know how to solve the problem so far.

richarbernal
  • 1,063
  • 2
  • 14
  • 32
JACK M
  • 2,627
  • 3
  • 25
  • 43

2 Answers2

1

you need a BroadcastReceiver that listens to the according broadcasts. see a similar question here.

Community
  • 1
  • 1
Dennis Winter
  • 2,027
  • 4
  • 32
  • 45
0

If you wish to control the volume of audio played through your app, make use of setVolumeControlStream() method. It directs volume key presses to the audio stream you specify.

setVolumeControlStream(AudioManager.STREAM_MUSIC);
Tony
  • 2,242
  • 22
  • 33