Skip to content

Commit 6845898

Browse files
committed
Merge pull request godotengine#107385 from Alex2782/fix_vibrate_android
Fix `Input.vibrate_handheld` on Android.
2 parents 53da681 + a1e12dc commit 6845898

File tree

1 file changed

+20
-16
lines changed
  • platform/android/java/lib/src/org/godotengine/godot

1 file changed

+20
-16
lines changed

platform/android/java/lib/src/org/godotengine/godot/Godot.kt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,25 +1011,29 @@ class Godot(private val context: Context) {
10111011
@Keep
10121012
private fun vibrate(durationMs: Int, amplitude: Int) {
10131013
if (durationMs > 0 && requestPermission("VIBRATE")) {
1014-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
1015-
if (amplitude <= -1) {
1016-
vibratorService.vibrate(
1017-
VibrationEffect.createOneShot(
1018-
durationMs.toLong(),
1019-
VibrationEffect.DEFAULT_AMPLITUDE
1014+
try {
1015+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
1016+
if (amplitude <= -1) {
1017+
vibratorService.vibrate(
1018+
VibrationEffect.createOneShot(
1019+
durationMs.toLong(),
1020+
VibrationEffect.DEFAULT_AMPLITUDE
1021+
)
10201022
)
1021-
)
1022-
} else {
1023-
vibratorService.vibrate(
1024-
VibrationEffect.createOneShot(
1025-
durationMs.toLong(),
1026-
amplitude
1023+
} else {
1024+
vibratorService.vibrate(
1025+
VibrationEffect.createOneShot(
1026+
durationMs.toLong(),
1027+
amplitude
1028+
)
10271029
)
1028-
)
1030+
}
1031+
} else {
1032+
// deprecated in API 26
1033+
vibratorService.vibrate(durationMs.toLong())
10291034
}
1030-
} else {
1031-
// deprecated in API 26
1032-
vibratorService.vibrate(durationMs.toLong())
1035+
} catch (e: SecurityException) {
1036+
Log.w(TAG, "SecurityException: VIBRATE permission not found. Make sure it is declared in the manifest or enabled in the export preset.")
10331037
}
10341038
}
10351039
}

0 commit comments

Comments
 (0)