Reputation: 11
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!
Upvotes: 1
Views: 476
Reputation: 11
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.
Upvotes: 0
Reputation: 1056
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.
Upvotes: 3