8

I am trying to enable the ringer normal mode and increase the volume programmatically.

AudioManager mobilemode = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
//   int streamMaxVolume = mobilemode.getStreamMaxVolume(AudioManager.STREAM_RING);
switch (mobilemode.getRingerMode()) {
    case AudioManager.RINGER_MODE_SILENT:
        Log.i("MyApp","Silent mode");

        mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        mobilemode.setStreamVolume (AudioManager.STREAM_MUSIC,mobilemode.getStreamMaxVolume(AudioManager.STREAM_MUSIC),0);
        break;
    case AudioManager.RINGER_MODE_VIBRATE:
        Log.i("MyApp","Vibrate mode");                     
        mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        mobilemode.setStreamVolume (AudioManager.STREAM_MUSIC,mobilemode.getStreamMaxVolume(AudioManager.STREAM_MUSIC),0);
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        Log.i("MyApp","Normal mode");
        break;
}

But It enable the normal mode. But I can not increase the volume.

enter image description here

Please let me any way to increase the volume programmatically..

Narendra Singh
  • 3,990
  • 5
  • 37
  • 78
  • I think in place of mobilemode.getStreamMaxVolume(AudioManager.STREAM_MUSIC), you just pass some value like in between 0 to 20 then it will ring based on that volume if you are getting from device then it will not be changed. – Hanuman May 25 '15 at 07:27

1 Answers1

16

Replace the line

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

with below line

mobilemode.setStreamVolume(AudioManager.STREAM_RING,audioManager.getStreamMaxVolume(AudioManager.STREAM_RING),0);
Chandrakanth
  • 3,711
  • 2
  • 18
  • 31