From 494925c96e41358050b8278f2ca1edabd2287d84 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Mon, 9 Aug 2021 11:43:56 +0200 Subject: [PATCH] fix: Always return `authorized` for requestPermission on SDK 22 and below (#344) --- .../main/java/com/mrousavy/camera/CameraViewModule.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt b/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt index 8a5f97c..e51da7c 100644 --- a/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt +++ b/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt @@ -287,6 +287,11 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase @ReactMethod fun requestCameraPermission(promise: Promise) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + // API 21 and below always grants permission on app install + return promise.resolve("authorized") + } + val activity = reactApplicationContext.currentActivity if (activity is PermissionAwareActivity) { val currentRequestCode = RequestCode++ @@ -306,6 +311,11 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase @ReactMethod fun requestMicrophonePermission(promise: Promise) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + // API 21 and below always grants permission on app install + return promise.resolve("authorized") + } + val activity = reactApplicationContext.currentActivity if (activity is PermissionAwareActivity) { val currentRequestCode = RequestCode++