2

In Android, there are normally 3 Audio Volume Channels interesting to the user: Music/Media, Ringtone, and Alarms. Normally, when pressing the hardware volume buttons, the ringtone volume gets set and a dialog with a seekbar is shown accordingly.

But if I have opened the Music app and press the volume buttons, the Media volume channel gets set (and a loudspeaker icon is shown on the seekbar dialog instead of a phone). My question now is, how can I set for my application that is uses the media channel volume control instead of the ringtone channel? Is there a switch for this or do I have to do this manually (catching the volume button strokes)?

joni
  • 5,402
  • 1
  • 27
  • 40

3 Answers3

8

After some googling, I found it out for myself.

You can call setVolumeControlStream in the onCreate method of your activity. Example below.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ...

    // change the music vol instead of ringtone vol
    // when hardware volume buttons are pressed
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
joni
  • 5,402
  • 1
  • 27
  • 40
0

For Stream music

AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);

For Ring tone

AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audio.getStreamVolume(AudioManager.STREAM_RING);

For more here

Community
  • 1
  • 1
Rajesh Rajaram
  • 3,271
  • 4
  • 29
  • 48
  • sorry, I don't want to get the volume, but I want to set which volume stream gets modified when the user presses the hardware volume keys. – joni Nov 09 '12 at 08:54
0

You use AudioManager and set one of the following:

STREAM_ALARM    //The audio stream for alarms
STREAM_DTMF         //The audio stream for DTMF Tones
STREAM_MUSIC    //The audio stream for music playback
STREAM_NOTIFICATION //The audio stream for notifications
STREAM_RING         //The audio stream for the phone ring
STREAM_SYSTEM   //The audio stream for system sounds
STREAM_VOICE_CALL

Like this:

myManager.getStreamVolume(AudioManager.STREAM_MUSIC);
Ben
  • 3,012
  • 1
  • 21
  • 25
  • sorry, I don't want to get the volume, but I want to set which volume stream gets modified when the user presses the hardware volume keys. – joni Nov 09 '12 at 08:53