Search code examples
androidinfinitemotorolaandroid-vibration

Android : The vibrator does not stop vibrating


I have a strange issue with the vibrator object.

Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(2 * DateUtils.SECOND_IN_MILLIS);

When the screen is on (even out of my app), it works just as expected. But if I turn the screen off by pressing once the power button, the vibrator does not stop vibrating after the 2 seconds. It continues to vibrate indefinitely.

Note that this behavior only happens on my Motorola Moto E3. Do you have any idea how I can circumvent this?


Solution

  • I tried everything (postdelayed, services, new thread, ...), without any success. But I finally found a way to circumvent this bug on the Motorola Moto E3, using a pattern :

    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(new long[]{0, 2 * DateUtils.SECOND_IN_MILLIS}, -1);
    

    I hope this helps.