28

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

4

5 回答 5

66

为您解决。

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);
于 2012-07-28T08:55:53.353 回答
9
//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);
于 2012-12-21T07:03:49.893 回答
6

解决方案:

AudioManager audio_mngr = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
audio_mngr .setRingerMode(AudioManager.RINGER_MODE_SILENT);
于 2012-07-28T08:56:03.687 回答
0

是的,这可以通过以下方式以编程方式关闭和开启静音模式:

AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

用于设置静音模式:

audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);

对于正常模式:

audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
于 2015-03-26T07:58:03.493 回答
0
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);

}
于 2015-06-03T19:50:43.557 回答