warning: [deprecation] vibrate(long[],int) in Vibrator has been deprecated

Reference:

https://developer.android.com/reference/android/os/Vibrator#vibrate(long), and following methods

These methods have been deprecated too:

public void vibrate (long milliseconds)
public void vibrate (long[] pattern, int repeat)
public void vibrate (VibrationEffect vibe, AudioAttributes attributes)
public void vibrate (long milliseconds, AudioAttributes attributes)
public void vibrate (long[] pattern, int repeat, AudioAttributes attributes)

These methods have been deprecated from API level 26 and have been superseded by these two new methods:

public void vibrate (VibrationEffect vibe, VibrationAttributes attributes)
public void vibrate (VibrationEffect vibe)

so you can safely manage this situation with:

if (Build.VERSION.SDK_INT >= 26) // new version
    vibrator.vibrate(createOneShot(1000, VibrationEffect.DEFAULT_AMPLITUDE));
else  // old version
    vibrator.vibrate(patternTiming, 0);

Related: https://www.cascablog.it/2024/04/01/warning-deprecation-vibrator_service-in-context-has-been-deprecated/

Leave a Reply

Your email address will not be published. Required fields are marked *