Hey, I'm thinking about adding haptic feedback (vibration) to my app. In the old Viewsystem I would have used view.performHapticFeedback(). Is there a way to do something similar using compose without doing it manually (using the vibrate permission and the Vibrator Systemservice)?
d
Diego Pappalardo
08/31/2020, 2:14 PM
you can get the root view
m
manueldidonna
08/31/2020, 2:14 PM
There is a
HapticFeedBackAmbient
n
Niklas Schnettler
08/31/2020, 2:16 PM
That is exactly what I was looking for, thank you
r
Roshan P Varghese
06/08/2021, 6:08 PM
Can you share how haptic vibration is done now?
I'm trying to provide haptic vibration for a button click in compose UI.
l
Luis Fer García
06/22/2021, 6:45 PM
Hey, I was looking for a solution too, here's what I did to make it happen:
Copy code
val vibratorService = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
if (Build.VERSION.SDK_INT >= 26) {
vibratorService.vibrate(VibrationEffect.createOneShot(25, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
vibratorService.vibrate(25)
}