Home > Blockchain >  How can we access all files from download directory in android 11 and above
How can we access all files from download directory in android 11 and above

Time:11-19

In below android 11 we can get the all files from public directory(Downloads) using File(getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)).listFiles() but in android 11 when i try to access files am getting files which are related to my application am unable to get all the files and how can we get all the files in android 11

am using this both permissions for reading and writing file

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

this is snippet for getting list

val files: Queue<File> = LinkedList()
val ROOT_DIR = getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath
files.addAll(File(ROOT_DIR).listFiles())

CodePudding user response:

Here is the full description on security updates for external storage access in Android 11 and above.

https://developer.android.com/about/versions/11/privacy/storage

CodePudding user response:

You have two options.

Or use 'all files access' using permission MANAGE_EXTERNAL_STORAGE.

Or let the user select the files using ACTION_,OPEN_DOCUMENT. Allow multiple.

  • Related