From 951d5510c2b70f994ecfafba16ae0311b4bb5d25 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Tue, 7 Jan 2025 12:47:30 -0800 Subject: [PATCH] GameActivity: check for VIBRATE permission on Android While we add this permission by default, if a developer sets custom permissions, we want to avoid crashing when we try to access an API that we don't have permission to use --- .../app/src/main/java/org/haxe/lime/GameActivity.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/templates/android/template/app/src/main/java/org/haxe/lime/GameActivity.java b/templates/android/template/app/src/main/java/org/haxe/lime/GameActivity.java index 3c28d7a6cb..18a276f6e5 100644 --- a/templates/android/template/app/src/main/java/org/haxe/lime/GameActivity.java +++ b/templates/android/template/app/src/main/java/org/haxe/lime/GameActivity.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.net.Uri; import android.os.Build; @@ -16,6 +17,7 @@ import android.view.KeyEvent; import android.view.View; import android.webkit.MimeTypeMap; +import android.Manifest; import org.haxe.extension.Extension; import org.libsdl.app.SDLActivity; @@ -110,7 +112,13 @@ protected void onCreate (Bundle state) { super.onCreate (state); assetManager = getAssets (); - vibrator = (Vibrator)mSingleton.getSystemService (Context.VIBRATOR_SERVICE); + + if (checkSelfPermission(Manifest.permission.VIBRATE) == PackageManager.PERMISSION_GRANTED) { + + vibrator = (Vibrator)mSingleton.getSystemService (Context.VIBRATOR_SERVICE); + + } + handler = new Handler (); Extension.assetManager = assetManager;