Reputation: 1034
Is there a method that makes the vibration not work through Vibrator.vibrate
method if the phone ring state is mute
so that I do not check it manually?
Upvotes: 0
Views: 162
Reputation: 346
check the states and do the work needed
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();
}
Upvotes: 4