1import android.os.Vibrator;
2...
3Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
4// Vibrate for 500 milliseconds
5if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
6 v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
7} else {
8 //deprecated in API 26
9 v.vibrate(500);
10}
11