From a1e12dca3f5466b28c7bd3230f8f2f278ed70d9a Mon Sep 17 00:00:00 2001 From: Alexander Hartmann Date: Wed, 11 Jun 2025 02:54:53 +0200 Subject: [PATCH] Fix `Input.vibrate_handheld` on Android. --- .../lib/src/org/godotengine/godot/Godot.kt | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt index a3c2f9a52f9..ebe4e8960ae 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt @@ -1011,25 +1011,29 @@ class Godot(private val context: Context) { @Keep private fun vibrate(durationMs: Int, amplitude: Int) { if (durationMs > 0 && requestPermission("VIBRATE")) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - if (amplitude <= -1) { - vibratorService.vibrate( - VibrationEffect.createOneShot( - durationMs.toLong(), - VibrationEffect.DEFAULT_AMPLITUDE + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (amplitude <= -1) { + vibratorService.vibrate( + VibrationEffect.createOneShot( + durationMs.toLong(), + VibrationEffect.DEFAULT_AMPLITUDE + ) ) - ) + } else { + vibratorService.vibrate( + VibrationEffect.createOneShot( + durationMs.toLong(), + amplitude + ) + ) + } } else { - vibratorService.vibrate( - VibrationEffect.createOneShot( - durationMs.toLong(), - amplitude - ) - ) + // deprecated in API 26 + vibratorService.vibrate(durationMs.toLong()) } - } else { - // deprecated in API 26 - vibratorService.vibrate(durationMs.toLong()) + } catch (e: SecurityException) { + Log.w(TAG, "SecurityException: VIBRATE permission not found. Make sure it is declared in the manifest or enabled in the export preset.") } } }