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.") } } }