是否可以在android中以编程方式关闭静音模式?

是否可以在Android中以编程方式关闭静音模式?

Solutions Collecting From Web of "是否可以在android中以编程方式关闭静音模式?"

解决方案给你。

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); 
 //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); 

解:

 AudioManager audio_mngr = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE); audio_mngr .setRingerMode(AudioManager.RINGER_MODE_SILENT); 
 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); } 

是的,这可以关闭和以编程方式在静音模式下面是代码:

 AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); 

用于设置静音模式:

 audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); 

对于普通模式:

 audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);