Ringer Mode Vibrate no Android

Question:

I wonder if it's possible to programmatically call setRingerMode(RINGER_MODE_VIBRATE) without the device vibrating at the time the method is called?

Android has a default behavior when we set the sound mode: vibrate when we select the RINGER_MODE_VIBRATE mode, directly on the device. And this behavior is also repeated when done via code.

When I open the app, the device's sound mode should be set to RINGER_MODE_NORMAL. But when I close, the previous state must be restored. When restoring the RINGER_MODE_VIBRATE state the phone vibrates.

I would like it not to vibrate when setting RINGER_MODE_VIBRATE. Is there any way to inhibit this vibration?

Answer:

Call the startVibrate method inside the method you expect to vibrate…

private void metodoQueVibra(){
  startVibrate();
}

public void startVibrate() {
  long pattern[] = { 0, 100, 200, 300, 400 };
  vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
  vibrator.vibrate(pattern, 0);
}

Reference:

http://www.compiletimeerror.com/2013/11/vibrate-android-device-with-example.html#.U_4eS_ldXp4

Scroll to Top