Reputation: 111
Since AudioManager.RINGER_MODE_VIBRATE
also silences the device, how do you turn on vibrate and keep the current volume level (e.g. if there's an incoming call the phone will vibrate AND play the ring tone)?
Thanks!
Upvotes: 1
Views: 408
Reputation: 22342
The easiest way I can think of is to use:
setVibrateSetting(AudioManagerVIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
Although the method was deprecated in API 16, I don't know a good replacement for it if you're looking to change the vibrate settings for more than your own app.
Just make sure that the ringer mode is on AudioManager.RINGER_MODE_NORMAL
as well.
Of course, you could also just set the ringer mode to AudioManager.RINGER_MODE_NORMAL
and bring up the settings page for the user to change the vibrate setting manually.
Upvotes: 1
Reputation: 4855
Review this code,
// Get instance of Vibrator from current Context
Vibrator vb = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Start immediately
// Vibrate for 200 milliseconds
// Sleep for 500 milliseconds
long[] pattern = { 0, 200, -1 };
// The "0" means to repeat the pattern starting at the beginning
// CUIDADO: If you start at the wrong index (e.g., 1) then your
// pattern
// will be off --
// You will vibrate for your pause times and pause for your vibrate
// times !
vb.vibrate(pattern, 0);
to stop, call
vb.cancel();
Note: vb.cancel() should not be called immediately after vb.vibrate(pattern, 0);
Upvotes: 0