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
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 に答える