How to pick image from shared storage in android 11 device?

8.7k Views Asked by At

I used this library https://github.com/Dhaval2404/ImagePicker and I got a warning from the android play console, team We've detected that your app contains the requestLegacyExternalStorage flag in the manifest file of 1 or more of your app bundles or APKs. Developers with apps on devices running Android 11+ must use Scoped Storage to give users better access control over their device storage. To release your app on Android 11 or newer after May 5th, you must either: 

2

There are 2 best solutions below

5
On
  • Before Android 10, we have a concept of Shared Storage. Every application in the device has some private storage in the internal memory and you can find this in the android/data/your_package_name directory. Apart from this internal storage, the rest of the storage is called the Shared Storage i.e. every application with the storage permission can access this part of the memory. This includes media collections and other files of different applications. But the problem is that the application having the storage permission doesn't require access to all of these files. All they want is to perform some small operation over some small part of the memory and that's it. For example, some application just needs to select a user image to upload it as the profile picture and nothing else. So, why provide them with full access to that Shared Storage?

  • Also, the second problem is that when the application is having such a wide writing capability on the storage then the files generated by the application gets scattered and when the user uninstalls the application then the files generated by the application remains in the storage only and are not deleted and takes a lot of space.

  • So, we need some kind of mechanism, with the help of which the apps can get the specific access they need without getting such a broad reading and writing power that they don't actually need. This can be done with the help of Scoped Storage.

Note:- From Android 11 onwards googles forces to used Scope Storage Check This Link

0
On
<queries>
<intent>
    <action android:name="android.intent.action.PICK" />
</intent>

Don't forget to put queries tag in your manifest file. use this code in your manifest file...