I completed one of my apps and started testing. But I identified that my app doesn't work in Android 11. I want to get the file list of a folder of another app and to read the items in them. But it returns an empty list although there are files in that folder.
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.status_saver">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<application
android:requestLegacyExternalStorage="true"
android:label="status_saver"
android:icon="@mipmap/ic_launcher">
This is how I read the files in the folder
var files = Directory( "storage/emulated/0/Android/media/com.whatsapp/WhatsApp/Media/.Statuses")
.listSync(recursive: true);
print(files);
This is how I request permission.
void _grantPermission() async {
var status = await Permission.storage.status;
if (status.isGranted) {
_getData();
} else {
await Permission.storage.request();
status = await Permission.storage.status;
_getData();
}
setState(() {
mainStatus = status.isGranted;
});
}
This is happening because of Android 11's scoped storage as I think.