Android Vibrate Is Deprecated. How To Use VibrationEffect In Android>= API 26?
Answer :
Amplitude is an int value. Its The strength of the vibration. This must be a value between 1 and 255, or DEFAULT_AMPLITUDE which is -1.
You can use it as VibrationEffect.DEFAULT_AMPLITUDE
More details here
with kotlin
private fun vibrate(){     val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {          vibrator.vibrate(VibrationEffect.createOneShot(200, VibrationEffect.DEFAULT_AMPLITUDE))     } else {          vibrator.vibrate(200)     } } You can use this for haptic feedback (vibration):
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); There are other constants available in HapticFeedbackConstants like VIRTUAL_KEY, KEYBOARD_TAP ... 
Comments
Post a Comment