Setting the Android System Volume

前端 未结 2 486
名媛妹妹
名媛妹妹 2021-01-06 09:32

I am writing an application which handles the following:

  1. Silent - Makes the phone volume silent
  2. Low - Makes the phone volume 1 point above the silent<
2条回答
  •  无人及你
    2021-01-06 10:11

    Add this in onCreate() method of your code and then play around with the 0 value to increase or decrease the volume where 0 means OFF.

    AudioManager mgr=null;
    
    mgr=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
    mgr.setStreamVolume(AudioManager.STREAM_MUSIC, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
    mgr.setStreamVolume(AudioManager.STREAM_RING, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
    mgr.setStreamVolume(AudioManager.STREAM_ALARM, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
    mgr.setStreamVolume(AudioManager.STREAM_SYSTEM, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
    mgr.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
    

提交回复
热议问题