Skip to content

Commit 47c958e

Browse files
authored
Merge pull request #2 from ryancrosby/android-photo-library-permissions
Ask for the minimum permission necessary when reading from the library
2 parents b8933f7 + cce4c2c commit 47c958e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

android/src/main/java/com/imagepicker/ImagePickerModule.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,16 @@ private boolean permissionsCheck(@NonNull final Activity activity,
573573
final int requestCode)
574574
{
575575
boolean permissionsGranted = true;
576-
boolean needsWritePermission = requestCode == REQUEST_PERMISSIONS_FOR_LIBRARY || PermissionUtils.needsExternalStoragePermission(options);
576+
boolean needsWritePermission = PermissionUtils.needsExternalStoragePermission(options);
577577

578578
String[] PERMISSIONS;
579579
switch (requestCode) {
580580
case REQUEST_PERMISSIONS_FOR_LIBRARY:
581-
PERMISSIONS = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
581+
if (needsWritePermission) {
582+
PERMISSIONS = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
583+
} else {
584+
PERMISSIONS = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE};
585+
}
582586
break;
583587
case REQUEST_PERMISSIONS_FOR_CAMERA:
584588
if (needsWritePermission) {
@@ -602,7 +606,15 @@ private boolean permissionsCheck(@NonNull final Activity activity,
602606

603607
if (!permissionsGranted)
604608
{
605-
final boolean dontAskAgain = ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) && ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA);
609+
boolean dontAskAgain = true;
610+
611+
// check if any of the permissions need to be requested
612+
for (String permission : PERMISSIONS) {
613+
if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
614+
dontAskAgain = false;
615+
break;
616+
}
617+
}
606618

607619
if (dontAskAgain)
608620
{

0 commit comments

Comments
 (0)