AudioManager.adjustStreamVolume no longer works on 6+ devices

So, I meet a strange problem in which the call to AudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI) no longer causes a change in the system volume on the device that I just upgraded to 6.0.

On all pre-6 devices, this code works as expected. I noticed changes in AudioManager where setStreamVolume is deprecated, but the suggested alternative is what I already used ...

At first, I thought that this could be a permission problem, since MODIFY_AUDIO_SETTINGS indicated as a dangerous permission, but I checked ContextCompat.checkSelfPermission(this, Manifest.Permission.MODIFY_AUDIO_SETTINGS) == PackageManager.PERMISSION_GRANTED (as well as there are no audio rights settings on the page permissions, so I'm assuming this is not the case).

I tried another recommended method, adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI) , but also did not give any results.

So, to clarify:

Nothing visually happens when calling adjustStreamVolume / adjustVolume and AudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) returns an unchanged value, as if it had never been called.

If anyone has any thoughts on this, I would love to hear them now.

Edit:

After posting this question, I switched to using setStreamVolume(AudioManager.STREAM_MUSIC, value, AudioManager.FLAG_SHOW_UI) , which works, although the docs say it is no longer needed.

I would like to think about it ...

Edit 2:

Opened a problem since I was able to replicate to another device

+7
java android
source share
1 answer

Just because it is out of date should not mean that it should stop working. It still supports backward compatibility.

Make sure you have installed AudioManager correctly:

 AudioManager audioManager =(AudioManager)getSystemService(Context.AUDIO_SERVICE); 

Then use this audio master to set the stream volume for the desired value:

 audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, desiredVolume, 0); 
0
source share

All Articles