0

I'm currently developing an app for personal use, not for release on the market. I need the 'manageExternalStorage' permission for my app, but I'm facing issues acquiring the permission.

pubspec.yaml

  permission_handler: ^10.4.3
  path_provider: ^2.1.0
  android_path_provider: ^0.3.0

Manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.fol">

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

   <application
        android:label="fol"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

code for requesting permission

 Future<void> createFileInDownloadFolder() async {
    var status1 = await Permission.storage.status;
    if (!status1.isGranted) {
      await Permission.storage.request();
    }
    var status2 = await Permission.manageExternalStorage.status;
    if (!status2.isGranted) {
      await Permission.manageExternalStorage.request();
    }

    print("stroage ${status1}");
    print("manageExternalStorage ${status2}");
  }
  @override
  void initState() {
    createFileInDownloadFolder();
  }

When I print the results, I get:

I/flutter (19674): storage PermissionStatus.granted I/flutter (19674): manageExternalStorage PermissionStatus.denied

The permissions shown in the app information are 'Photos and Videos' and 'Music and Audio'.

Perhaps due to the lack of permission, when I try to list files in the root directory (/storage/emulated/0/) or in the Downloads (/storage/emulated/0/Download/) directory, only folders are shown. No files are visible.

Here's the code I'm using to list the folders and files:

List<FileSystemEntity> tmpfilelistz = Directory("/storage/emulated/0/Download/").listSync();
print(tmpfilelistz);

How do I get permissions and make all files appear in the list? Help me!

I have tried using chatGPT and have continued to search on Google, but I still can't figure it out.

0 Answers0