在开启该应用的时候会自动将手机情景模式切换成静音模式,并在关闭或者时间到的时候,将情景模式切换成开启之前的模式。
public void setPhoneMode() { //得到AudioManager对象,并设置成静音模式 //记录当前的手机情景模式 ringerMode = audioManager.getRingerMode(); vibrate_type_ringer = audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER); vibrate_type_notification = audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION); //设置为静音模式 audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF); audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF); Log.i(TAG, "setPhoneMode"); }在关闭的时候自动切换成原来的模式:
public void close() { if(helper) { mEndCall = false ; helper = false ; onOffShow.setText("关"); am.cancel(alarmIntent); //还原情景模式 audioManager.setRingerMode(ringerMode); audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, vibrate_type_ringer); audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, vibrate_type_notification); Log.i(TAG, "helper close"); } Log.i(TAG, "close"); }