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

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

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

5条回答
  •  我在风中等你
    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);
    
    }
    

提交回复
热议问题