From 7101772fd9c8c70d1b286985561cc1733c51af53 Mon Sep 17 00:00:00 2001 From: Yedidya Kennard Date: Wed, 24 Aug 2016 13:24:12 +0300 Subject: [PATCH] Added hasCameraPermission on Android --- .../java/com/wix/RNCameraKit/camera/CameraModule.java | 9 +++++++++ src/CameraKitCamera.android.js | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/android/src/main/java/com/wix/RNCameraKit/camera/CameraModule.java b/android/src/main/java/com/wix/RNCameraKit/camera/CameraModule.java index 1b9e55f..710120e 100644 --- a/android/src/main/java/com/wix/RNCameraKit/camera/CameraModule.java +++ b/android/src/main/java/com/wix/RNCameraKit/camera/CameraModule.java @@ -1,6 +1,8 @@ package com.wix.RNCameraKit.camera; +import android.Manifest; import android.hardware.Camera; +import android.support.v4.content.PermissionChecker; import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; @@ -60,4 +62,11 @@ public class CameraModule extends ReactContextBaseJavaModule { public void capture(boolean saveToCameraRoll, final Promise promise) { new Capture(getReactApplicationContext()).execute(promise); } + + @ReactMethod + public void hasCameraPermission(Promise promise) { + boolean hasPermission = PermissionChecker.checkSelfPermission(getReactApplicationContext(), Manifest.permission.CAMERA) + == PermissionChecker.PERMISSION_GRANTED; + promise.resolve(hasPermission); + } } diff --git a/src/CameraKitCamera.android.js b/src/CameraKitCamera.android.js index c091af6..9e2dbba 100644 --- a/src/CameraKitCamera.android.js +++ b/src/CameraKitCamera.android.js @@ -42,4 +42,9 @@ export default class CameraKitCamera extends React.Component { return success; } + static async hasCameraPermission() { + const success = await NativeCameraModule.hasCameraPermission(); + return success; + } + }