1

When using headphones I can't adjust the volume for the device to the maximum possible setting anymore, probably due to EU safety regulations.

public void SetVolume(int StreamType, int Volume)
    {
    AudioManager gameAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    gameAudioManager.setStreamVolume(StreamType,Volume,0);
    }

This is the code I'm using to adjust the volume. It works just fine when using the built-in speakers. But as soon as headphones are plugged in, I can't raise the volume to the maximum level the device allows with built in speakers.

I know that with getStreamMaxVolume I can get the max volume of the stream, but without headphones it's a range from 0-15 and with headphones it seems it only accepts a range from 0-9. But when using the volume buttons on the device I can max out the 0-15 range even with headphones plugged in.

Sadly I couldn't find anything in the Android documentation, but that's probably due to my lack of knowledge. Any hints would be greatly appreciated!

DrToboggan
  • 11
  • 2

2 Answers2

3

You are correct, Android does not allow programmers to programmatically increase the volume to maximum levels when headphone is plugged-in for safety reasons.

This is why in certain phone models when user is trying to increase past the level 9 volume mark, a warning will appear to warn the user about exceeding safe hearing level.

You might want to make your application accommodate to this limitation as it is a safety feature enforced at OS-level in Android.

Lee Boon Kong
  • 1,007
  • 1
  • 8
  • 17
  • 1
    Yes there is not much to do, on my phone, which is an old model, after certain time listening to high volume, the volume lowers automatically to half when the headphones are plugged. It is quite annoying because my headphones have a low output.. – Kaddath Mar 30 '23 at 08:48
  • I understand it's a safety feature and I see the reason behind it. Sadly adjusting the application in this instance would probalby result in too much work, which is why I was looking for a workaround in the first place. In the future we will absolutely keep this in mind though! Thank you :) – DrToboggan Mar 30 '23 at 16:40
0

Found a workaround for now using adjustStreamVolume - when using this function it seems to mimic the behaviour of the device buttons. Might run into problems with this later, but for now it works.

DrToboggan
  • 11
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 05 '23 at 02:11