Android BroadCastReceiver for volume key up and down

The intent does not have an EXTRA_KEY_EVENT extra. It does have an extra android.media.EXTRA_VOLUME_STREAM_VALUE which contains the new volume.

int volume = (Integer)intent.getExtras().get("android.media.EXTRA_VOLUME_STREAM_VALUE");

If you store the old value, you can infer whether volume up or down was pressed.

Leave a Comment