是否存在一种方法,如果电话响铃状态为Vibrator.vibrate
,则振动无法通过mute
方法工作,以便我不会手动检查?
答案 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();
}