I have asked for permission in Manifest:
<uses-permission android:name="android.permission.VIBRATE" />
I have implemented the same code as this example.
Vibrator vib = (Vibrator) mContext.getSystemService(VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vib.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
Log.i("AppInfo", "Vibrate 26+");
} else {
// deprecated in API 26
vib.vibrate(1000);
Log.i("AppInfo", "Vibrate <26");
}
This works for Android version below 26, but it's not working for version above. I have tried several devices and none of them are vibrating. In the log I can find the AppInfo showing that the code is running, but no vibration. Why is this not working? This code seems correct.