// Vibrate for 150 milliseconds private void shakeItBaby() {     if (Build.VERSION.SDK_INT >= 26) {         ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(150, VibrationEffect.DEFAULT_AMPLITUDE));     } else {         ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(150);     } } 

Read more of this post