Add video/audio authorization check for Android (#513)

* Add video/audio authorization check for Android

This only checks for the permission and no request is made. `PermissionAndroid` in recent React Native or manually asking it from native code can still be used.

* Add checkDeviceAuthorizationStatus
This commit is contained in:
Üstün Ergenoglu 2016-12-14 19:52:25 +02:00 committed by Zack Story
parent f696610115
commit 877ce2e6b2
1 changed files with 28 additions and 0 deletions

View File

@ -608,6 +608,34 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
}
}
}
@ReactMethod
public void checkDeviceAuthorizationStatus(final Promise promise) {
if (!checkForPermission(Manifest.permission.CAMERA)) {
promise.resolve(false);
} else {
promise.resolve(checkForPermission(Manifest.permission.RECORD_AUDIO));
}
}
@ReactMethod
public void checkVideoAuthorizationStatus(final Promise promise) {
promise.resolve(checkForPermission(Manifest.permission.CAMERA));
}
@ReactMethod
public void checkAudioAuthorizationStatus(final Promise promise) {
promise.resolve(checkForPermission(Manifest.permission.RECORD_AUDIO));
}
private boolean checkForPermission(String permission) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
}
int p = ContextCompat.checkSelfPermission(getReactApplicationContext(), permission);
return p == PackageManager.PERMISSION_GRANTED;
}
@ReactMethod
public void capture(final ReadableMap options, final Promise promise) {