Back
It's too simple, just try:
import android.os.Vibrator;...Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);// Vibrate for 500 millisecondsif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));} else { //deprecated in API 26 v.vibrate(500);}
import android.os.Vibrator;
...
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
//deprecated in API 26
v.vibrate(500);
}
Also add permission in AndroidManifest.xml file:
<uses-permission android:name="android.permission.VIBRATE"/>
31k questions
32.8k answers
501 comments
693 users