Is there any way to listen for volume changes with an Android service and react to that?
Btw: How does the Google music app allow the user to control the media volume even when the music is playing in the background?
Is there any way to listen for volume changes with an Android service and react to that?
Btw: How does the Google music app allow the user to control the media volume even when the music is playing in the background?
Check out
registerMediaButtonEventReceiver(ComponentName broadcastReceiver);
Define a
BroadcastReceiver
that handlesACTION_MEDIA_BUTTON
. The recievedintent
includes a single extra field,EXTRA_KEY_EVENT
, containing the key event that caused the broadcast. You can use this key event to get which key was pressed.EDIT:
This is just a sample code. syntax errors may be there.
Unregister the receiver in
onPause()
oronStop()