Skip to content

Commit 4d707a7

Browse files
fix(camera): requestPermissions on Android 13+ (#2393)
1 parent 50e7205 commit 4d707a7

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

camera/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,7 @@ private void cameraPermissionsCallback(PluginCall call) {
256256

257257
@Override
258258
protected void requestPermissionForAliases(@NonNull String[] aliases, @NonNull PluginCall call, @NonNull String callbackName) {
259-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
260-
for (int i = 0; i < aliases.length; i++) {
261-
if (aliases[i].equals(SAVE_GALLERY)) {
262-
aliases[i] = PHOTOS;
263-
}
264-
}
265-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
259+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
266260
for (int i = 0; i < aliases.length; i++) {
267261
if (aliases[i].equals(SAVE_GALLERY)) {
268262
aliases[i] = READ_EXTERNAL_STORAGE;
@@ -809,11 +803,14 @@ public void requestPermissions(PluginCall call) {
809803
} catch (JSONException e) {}
810804
}
811805

812-
if (permsList != null && permsList.size() == 1 && (permsList.contains(CAMERA) || permsList.contains(PHOTOS))) {
813-
// the only thing being asked for was the camera so we can just return the current state
806+
if (
807+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ||
808+
(permsList != null && permsList.size() == 1 && (permsList.contains(CAMERA) || permsList.contains(PHOTOS)))
809+
) {
810+
// either we're on Android 13+ (storage permissions do not apply)
811+
// or the only thing being asked for was the camera so we can just return the current state
814812
checkPermissions(call);
815813
} else {
816-
// we need to ask about gallery so request storage permissions
817814
requestPermissionForAlias(SAVE_GALLERY, call, "checkPermissions");
818815
}
819816
}

0 commit comments

Comments
 (0)