Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a listener to listen for changes in the volume in android?

Tags:

android

audio

Is it possible to register a listener to listen for changes in the volume level of the music stream in Android?

I'm displaying the actual volume in a SeekBar and I would like to change the seekbar if the user changes the volume with the hardware volume keys. At the moment the correct volume is displayed until the user changes the volume with hardware keys.

like image 847
Janusz Avatar asked Jul 05 '10 14:07

Janusz


People also ask

How to change volume in Android studio?

By default, pressing the volume control modifies the volume of the active audio stream. If your app isn't currently playing anything, hitting the volume keys adjusts the music volume (or the ringer volume before Android 9). Unless your app is an alarm clock, you should play audio with usage AudioAttributes.

What is media volume on an Android phone?

Under "Media volume," tap Play media to. When you press a volume button, the volume that changes depends on what you're doing. For example, if you're watching a movie, the movie volume changes. If you press your volume buttons when you're not listening to anything, your media volume changes.


1 Answers

This is not a perfect answer but a hack:

android.media.VOLUME_CHANGED_ACTION

I found above action in native logs while changing volume via hard volume key.

01-25 16:11:24.015: DEBUG/VolumePanel(189): onVolumeChanged(streamType: 2, flags: 4)
01-25 16:11:24.015: DEBUG/BluetoothA2dpService(189): Received intent with action: android.media.VOLUME_CHANGED_ACTION

so go ahead and register BroadcastReceiver with action "android.media.VOLUME_CHANGED_ACTION" if you don't have any other solution.

Other way of doing is; Taking over the volume key on Android .

like image 161
Jayesh Tembhekar Avatar answered Oct 22 '22 13:10

Jayesh Tembhekar