10

Imagepicker package says

No configuration required - the plugin should work out of the box.

It is no longer required to add android:requestLegacyExternalStorage="true" as an attribute to the tag in AndroidManifest.xml, as image_picker has been updated to make use of scoped storage.

reading images from gallery. so I think I need to ask some permission from the user as playstore also says this New package is just working and not asking for any permission. What permissions I need to explicitly ask And I don't want to save it on any external directory I just want to upload image to firebase storage Edit: image picker is not asking any permission from the user is this wrong

Noobdeveloper
  • 405
  • 2
  • 6
  • 19

2 Answers2

12

Permission needed to read and write files in the android are.
These permission are required to be added to your AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

In your scenario, you don't need to do anything as this is already handled by the library
https://pub.dev/packages/image_picker

Above mentioned library doesn't save the image in external storage.

Note: Images and videos picked using the camera are saved to your application's local cache, and should therefore be expected to only be around temporarily. If you require your picked image to be stored permanently, it is your responsibility to move it to a more permanent location.

For more info you can refer to this link
https://guides.codepath.com/android/Accessing-the-Camera-and-Stored-Media#accessing-stored-media

Update : How image picking is handled internally in image_picker for Android

For Gallery pick it opens in inbuild file picker intent using ACTION_GET_CONTENT(about action get content)

When opening file using ACTION_GET_CONTENT - Because the user is involved in selecting the files or directories that your app can access, this mechanism doesn't require any system permissions. You can read more about when permission is needed and when not in google docs

Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
  pickImageIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
pickImageIntent.setType("image/*");

activity.startActivityForResult(pickImageIntent, REQUEST_CODE_CHOOSE_MULTI_IMAGE_FROM_GALLERY);

and copies the result URI in temp file in cache directory and return the path

     String extension = getImageExtension(context, uri);
      inputStream = context.getContentResolver().openInputStream(uri);
      file = File.createTempFile("image_picker", extension, context.getCacheDir());
      file.deleteOnExit();
      outputStream = new FileOutputStream(file);
      if (inputStream != null) {
        copy(inputStream, outputStream);
        success = true;
      }
 

For Camera library request the camera permission android.permission.CAMERA from the user and save the camera image in app cache directory.

private void handleCaptureImageResult(int resultCode) {
    if (resultCode == Activity.RESULT_OK) {
      fileUriResolver.getFullImagePath(
          pendingCameraMediaUri != null
              ? pendingCameraMediaUri
              : Uri.parse(cache.retrievePendingCameraMediaUriPath()),
          new OnPathReadyListener() {
            @Override
            public void onPathReady(String path) {
              handleImageResult(path, true);
            }
          });
      return;
    }

    // User cancelled taking a picture.
    finishWithSuccess(null);
  }

This code is as per version image_picker: ^0.8.4+4 code present on their github page - image picker code

Nitish
  • 3,075
  • 3
  • 13
  • 28
  • 1
    but in my case image picker is not asking any permissions from the user is this policy threat for playstore – Noobdeveloper Sep 22 '21 at 09:05
  • @Noobdeveloper , no it's not a threat to playstore policy , as in latest updates of image_picker opens the inbuild device gallery intent using 'Intent pickVideoIntent = new Intent(Intent.ACTION_GET_CONTENT);' and created a temp file and path from the result content uri and returns us the image path. Code for this is present on their github page - [imagePickerCode](https://github.com/flutter/plugins/blob/master/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java) – Nitish Sep 22 '21 at 10:36
  • So it means I don't have to anything in manifest – Noobdeveloper Sep 22 '21 at 10:53
  • 1
    No , nothing to do in the manifest – Nitish Sep 22 '21 at 11:18
  • App info section says no permission requested. And even in runtime app is not asking any permission to read gallery. This url says need read external storage permission https://developer.android.com/training/data-storage. And also when I am adding read permission it's saying denied and app is still working fine and not asking that request when needed. What to do only thing I am considered of playstore policy. Please suggest – Noobdeveloper Nov 09 '21 at 09:20
  • https://developer.android.com/training/data-storage/shared/documents-files - refer to this link , this explain why permission is not required and cases when you might require the permission – Nitish Nov 09 '21 at 10:07
  • 1
    When opening file using `ACTION_GET_CONTENT` - Because the user is involved in selecting the files or directories that your app can access, this mechanism doesn't require any system permissions.. You can also refer to this answer - [read permission ever required to read uri from intent action](https://stackoverflow.com/questions/50826019/is-read-external-storage-permission-ever-required-to-read-uri-from-intent-action/50826220) – Nitish Nov 09 '21 at 10:13
  • Hey now comes another question about data protection section https://developer.android.com/guide/topics/data/collect-share#photos-videos they are saying if you're collecting photos you should add or something like that and in flutter we are not doing that please help. – Noobdeveloper Nov 13 '21 at 13:14
  • I didn't get your point , add what? Are you talking about permission or permission declaration to user. – Nitish Nov 14 '21 at 07:23
  • https://stackoverflow.com/questions/69960083/image-picker-permission-android-flutter check this post please – Noobdeveloper Nov 14 '21 at 07:31
0

You’ll have to add the above-mentioned permissions to your AndroidManifest.xml file. That is still required to access user storage.

  • After adding those two permissions. Still, my app is not asking permission in the runtimes. even I checked in my app permissions setting its saying denied and my app is running fine – Noobdeveloper Nov 08 '21 at 15:47