当手机静音时,让Vibrator.vibrate不做任何事 - Android

时间:2016-11-09 17:18:19

标签: android mute vibration

是否存在一种方法,如果电话响铃状态为Vibrator.vibrate,则振动无法通过mute方法工作,以便我不会手动检查?

1 个答案:

答案 0 :(得分:4)

检查状态并完成所需的工作

    AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    if (am.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
        Toast.makeText(this, "cannot vibrate already muted", Toast.LENGTH_SHORT).show();
    } else {
        Vibrator vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(2000);
        Toast.makeText(this, "I'm running", Toast.LENGTH_SHORT).show();  
    }