Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive volume changed events for the voice (in-call) stream type?

Tags:

android

I'm trying to register a broadcast receiver to handle the VOLUME_CHANGED_ACTION event, only for the volume_voice stream type (which I empirically see to be index 0 in Settings.System.VOLUME_SETTINGS).

The label EXTRA_VOLUME_STREAM_TYPE is hidden, so I have used the explicit string "android.media.EXTRA_VOLUME_STREAM_TYPE" instead. It all worked fine on Android 2.3.4 (got value 0 for volume_voice as expected), but on 2.3.5 the value that this extra holds is 10, which gives an ArrayIndexOutOfBoundsException on Settings.System.VOLUME_SETTINGS. Moreover, I see that volume_voice is still index 0 in Settings.System.VOLUME_SETTINGS.

Is there a more robust way to handle VOLUME_CHANGED_ACTION for volume_voice stream types?

Edit Or any other way to do what the title asks for?

like image 527
Michael Litvin Avatar asked Jan 23 '12 13:01

Michael Litvin


People also ask

How do I request audio focus on android?

The requestAudioFocus() method also requires an AudioManager. OnAudioFocusChangeListener . This listener should be created in the same activity or service that owns your media session. It implements the callback onAudioFocusChange() that your app receives when some other app acquires or abandons audio focus.

Which of the following will set the volume of the currently playing sound?

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).


1 Answers

I'm trying to register a broadcast receiver to handle the VOLUME_CHANGED_ACTION event

There is no VOLUME_CHANGED_ACTION in the Android SDK.

The label EXTRA_VOLUME_STREAM_TYPE is hidden, so I have used the explicit string "android.media.EXTRA_VOLUME_STREAM_TYPE" instead.

There is no EXTRA_VOLUME_STREAM_TYPE in the Android SDK.

Is there a more robust way to handle VOLUME_CHANGED_ACTION for volume_voice stream types?

There is no VOLUME_CHANGED_ACTION in the Android SDK.

Whatever you are trying to do is undocumented, unsupported, may not work on any given version of Android (past/present/future), and may not work on any given device (since manufacturers can change anything that is not in the SDK). It will never be "robust", by definition.

like image 145
CommonsWare Avatar answered Sep 28 '22 02:09

CommonsWare