0

I use the Ringtone class to play an alarm when some events occur in an application I'm writing.

Everything works perfectly but for the issue that even if I set the volume to maximum (from the phone interface) it is still a little too low. Can I programmatically set a louder volume?

mariosangiorgio
  • 5,520
  • 4
  • 32
  • 46

2 Answers2

1

You can use the following snippet, using AudioManager:

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

am.setStreamVolume(
    AudioManager.STREAM_MUSIC,
    am.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
    0);

This sets the volume to the maximum level (getStreamMaxVolume()) for the STREAM_MUSIC (which is on example a song played). For other types of sounds, use different value, like STREAM_RING etc.

Jeffy Lazar
  • 1,903
  • 13
  • 20
1

Try to use the AudioManager Class:

AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume (AudioManager.STREAM_MUSIC,audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC),0);

Hope I could help.

HappyDump
  • 443
  • 9
  • 18
  • I see that `AudioManager` has different streams and that `STREAM_MUSIC` is among the ones with the highest maximum volume. Does it mean that if I set my `Ringtone` to play on a `STREAM_MUSIC` it is the loudest I can make it? – mariosangiorgio Oct 29 '13 at 22:33