Hey, I'm thinking about adding haptic feedback (vi...
# compose
n
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
you can get the root view
m
There is a
HapticFeedBackAmbient
n
That is exactly what I was looking for, thank you
r
Can you share how haptic vibration is done now? I'm trying to provide haptic vibration for a button click in compose UI.
l
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)
}
389 Views