0

My app requires me to modify the volume of alarm stream when incoming call has been received, and voice transmission between two parties is going on.

I used this code:

    audioManager.setStreamVolume(AudioManager.STREAM_ALARM,volume,AudioManager.FLAG_PLAY_SOUND);
        Log.d("Track","Volume set to : "+audioManager.getStreamVolume(AudioManager.STREAM_ALARM));

The log message shows me that volume is being set properly. However, if I check alarm volume in the phone, it hasn't updated.

What should I do to make sure update happens properly in this scenario?

SoulRayder
  • 5,072
  • 6
  • 47
  • 93

1 Answers1

0

Try these snippets:

AudioManager mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, AudioManager.FLAG_PLAY_SOUND);

// or
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, AudioManager.FLAG_SHOW_UI);

// or
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, AudioManager.FLAG_VIBRATE);

Source: https://www.b4x.com/android/forum/threads/programatically-change-volume.7754/

Roberto Tellez Ibarra
  • 2,146
  • 3
  • 18
  • 34