I'm trying to get if haptic feedback enabled in System Settings, i.e. globally on a device. I don't need to set this setting, just read.
We do it this way on Android 12 or lower:
Settings.System.getInt(context.contentResolver, Settings.System.HAPTIC_FEEDBACK_ENABLED) == 1
But with the release of Android 13 Google deprecated flag HAPTIC_FEEDBACK_ENABLED
. Now it recommended to use android.os.VibrationAttributes.USAGE_TOUCH
.
It's really incomprehensible how to use it.
I need something like this:
val hapticEnabled: Boolean
get() = if (BuildConfig.VERSION_CODE >= Build.VERSION_CODES.TIRAMISU) {
// here what I'm trying to find out
} else {
Settings.System.getInt(context.contentResolver, Settings.System.HAPTIC_FEEDBACK_ENABLED) == 1
}