From 614753303fa8c642049b173e1626dbc476f9491a Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Wed, 25 Jan 2023 18:30:47 +0100 Subject: [PATCH] Fix crash when permissionRequestResult gets cancelled --- .../card_locker/LoyaltyCardEditActivity.java | 14 +++++++------- .../java/protect/card_locker/ScanActivity.java | 6 ++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java index 075d54e82..853c1209c 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java @@ -988,46 +988,46 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity { } public void onMockedRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - boolean allowed = grantResults[0] == PackageManager.PERMISSION_GRANTED; + boolean granted = grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED; Integer failureReason = null; if (requestCode == PERMISSION_REQUEST_CAMERA_IMAGE_FRONT) { - if (allowed) { + if (granted) { takePhotoForCard(Utils.CARD_IMAGE_FROM_CAMERA_FRONT); return; } failureReason = R.string.cameraPermissionRequired; } else if (requestCode == PERMISSION_REQUEST_CAMERA_IMAGE_BACK) { - if (allowed) { + if (granted) { takePhotoForCard(Utils.CARD_IMAGE_FROM_CAMERA_BACK); return; } failureReason = R.string.cameraPermissionRequired; } else if (requestCode == PERMISSION_REQUEST_CAMERA_IMAGE_ICON) { - if (allowed) { + if (granted) { takePhotoForCard(Utils.CARD_IMAGE_FROM_CAMERA_ICON); return; } failureReason = R.string.cameraPermissionRequired; } else if (requestCode == PERMISSION_REQUEST_STORAGE_IMAGE_FRONT) { - if (allowed) { + if (granted) { selectImageFromGallery(Utils.CARD_IMAGE_FROM_FILE_FRONT); return; } failureReason = R.string.storageReadPermissionRequired; } else if (requestCode == PERMISSION_REQUEST_STORAGE_IMAGE_BACK) { - if (allowed) { + if (granted) { selectImageFromGallery(Utils.CARD_IMAGE_FROM_FILE_BACK); return; } failureReason = R.string.storageReadPermissionRequired; } else if (requestCode == PERMISSION_REQUEST_STORAGE_IMAGE_ICON) { - if (allowed) { + if (granted) { selectImageFromGallery(Utils.CARD_IMAGE_FROM_FILE_ICON); return; } diff --git a/app/src/main/java/protect/card_locker/ScanActivity.java b/app/src/main/java/protect/card_locker/ScanActivity.java index 0b394df2b..4e6f17762 100644 --- a/app/src/main/java/protect/card_locker/ScanActivity.java +++ b/app/src/main/java/protect/card_locker/ScanActivity.java @@ -286,10 +286,12 @@ public class ScanActivity extends CatimaAppCompatActivity { } public void onMockedRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + boolean granted = grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED; + if (requestCode == CaptureManager.getCameraPermissionReqCode()) { - showCameraPermissionMissingText(grantResults[0] != PackageManager.PERMISSION_GRANTED); + showCameraPermissionMissingText(!granted); } else if (requestCode == PERMISSION_SCAN_ADD_FROM_IMAGE) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + if (granted) { addFromImageAfterPermission(); } else { Toast.makeText(this, R.string.storageReadPermissionRequired, Toast.LENGTH_LONG).show();