Is it possible to turn off the silent mode programmatically in android?

后端 未结 5 1017
轮回少年
轮回少年 2021-01-30 17:45

Is it possible to turn off the silent mode programmatically in Android?

相关标签:
5条回答
  • 2021-01-30 18:12

    Solution:

    AudioManager audio_mngr = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
    audio_mngr .setRingerMode(AudioManager.RINGER_MODE_SILENT);
    
    0 讨论(0)
  • 2021-01-30 18:16
    int normal = 2;
    int vibrate = 1;
    int silent = 0;
    int RingerMode;
    public static AudioManager AUDIOMANAGER;
    
    @Override
    public void onCreate() {
        super.onCreate();
    
        AUDIOMANAGER= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
        if (AUDIOMANAGER.getRingerMode() == normal) {
                        AUDIOMANAGER.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                        RingerMode = normal;
        } else if (AUDIOMANAGER.getRingerMode() == vibrate) {
                        AUDIOMANAGER.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                        RingerMode = vibrate;
                    }
        //And after do all your jobs..... you can return to previous mode:
                        AUDIOMANAGER.setRingerMode(RingerMode);
    
    }
    
    0 讨论(0)
  • 2021-01-30 18:17
    //SilentToNomal and NormalToSilent device Programatically
     final AudioManager mode = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    //Silent Mode Programatically
    mode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    
    //Normal Mode Programatically
      mode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    
    0 讨论(0)
  • 2021-01-30 18:26

    Solution for you .

    AudioManager am;
    am= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
    
    //For Normal mode
    am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    
    //For Silent mode
    am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    
    //For Vibrate mode
    am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
    
    0 讨论(0)
  • 2021-01-30 18:26

    Yes this is possible to turn off and on the silent mode programmatically below is the code :

    AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    

    for setting silent mode :

    audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    

    For normal mode :

    audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    
    0 讨论(0)
提交回复
热议问题