Reputation: 5543
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?
Upvotes: 0
Views: 972
Reputation: 453
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.
Upvotes: 1
Reputation: 1923
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.
Upvotes: 1