-1

When I try to access the contents of a hidden folder using directory, I get empty contents when trying to access hidden folders (starts with '.'). I've already added Read and Write permission to external storage inside AndroidMainifest.xml. The only possible solution I could see is to add "MANAGE_EXTERNAL_STORAGE" permission inside AndroidMainifest but I doubt if I can publish the app to play store using this permission or not. Below is attached code.

final directory = Directory(
        "/storage/emulated/0/Android/media/com.whatsapp/WhatsApp/Media/.Statuses");
    if (directory.existsSync()) {
      final items = directory.listSync();
      log(items.toString());   //empty list here in items
    }

Is there any way to access hidden folders apart from using MANAGE_EXTERNAL_STORAGE permission? Or can we request access to a specific folder in Flutter?

Miamy
  • 2,162
  • 3
  • 15
  • 32
shyam__
  • 1
  • 3

2 Answers2

0

Android 11 introduced many restrictions for accessing files that don't belong to an individual app's system-provided directory. You can read more about this here.

For example, apps targeting Android 11 are now not able to access files in directories belonging to other apps.

Android 11 has also made using many of the permission requests (like the ones below) obsolete. That being said, you should keep these requests in your android manifest so your app will have permission when running on devices running older versions of Android.

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Firas AT
  • 428
  • 3
  • 4
  • I have already added READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions but with these I'm only able to access folders that are not hidden – shyam__ Apr 03 '23 at 18:19
  • Unfortunately, you can no longer access folders that don't belong to your app no matter with Android 11. I suggest changing your approach. – Firas AT Apr 03 '23 at 21:58
0

As Firas AT has already said , you can not read files from other app directories which is inside the android folder for android version 11 and above.

Alternatively, if you want to access every other folder excluding the android directory,

you can checkout this

How To Exclude Android Directory, When Listing files/folders from Android device Using Flutter?