Merge pull request #107385 from Alex2782/fix_vibrate_android
Fix `Input.vibrate_handheld` on Android.
This commit is contained in:
commit
6845898461
@ -1011,25 +1011,29 @@ class Godot(private val context: Context) {
|
|||||||
@Keep
|
@Keep
|
||||||
private fun vibrate(durationMs: Int, amplitude: Int) {
|
private fun vibrate(durationMs: Int, amplitude: Int) {
|
||||||
if (durationMs > 0 && requestPermission("VIBRATE")) {
|
if (durationMs > 0 && requestPermission("VIBRATE")) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
try {
|
||||||
if (amplitude <= -1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
vibratorService.vibrate(
|
if (amplitude <= -1) {
|
||||||
VibrationEffect.createOneShot(
|
vibratorService.vibrate(
|
||||||
durationMs.toLong(),
|
VibrationEffect.createOneShot(
|
||||||
VibrationEffect.DEFAULT_AMPLITUDE
|
durationMs.toLong(),
|
||||||
|
VibrationEffect.DEFAULT_AMPLITUDE
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
} else {
|
||||||
|
vibratorService.vibrate(
|
||||||
|
VibrationEffect.createOneShot(
|
||||||
|
durationMs.toLong(),
|
||||||
|
amplitude
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
vibratorService.vibrate(
|
// deprecated in API 26
|
||||||
VibrationEffect.createOneShot(
|
vibratorService.vibrate(durationMs.toLong())
|
||||||
durationMs.toLong(),
|
|
||||||
amplitude
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else {
|
} catch (e: SecurityException) {
|
||||||
// deprecated in API 26
|
Log.w(TAG, "SecurityException: VIBRATE permission not found. Make sure it is declared in the manifest or enabled in the export preset.")
|
||||||
vibratorService.vibrate(durationMs.toLong())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user