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.