Cannot access hidden folder on android version 11 and later devices in flutter

734 Views Asked by At

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?

2

There are 2 best solutions below

2
Firas AT On

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"/>
0
Augustus kekule On

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?