skip to Main Content

Tried to open .pdf file like

ElevatedButton(
    onPressed: () async {
                  await OpenFile.open('/storage/emulated/0/Download/myqr.pdf')
                      .then((value) {
                    log(value.message.toString());
                  });
                },
    child: const Text("Open File"),
)

But not working.

It gives error: Permission denied: android.permission.READ_EXTERNAL_STORAGE

Already added permisions in AndroidMenifest.xml

<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"/>

Requested permissons:

Future askRequiredPermission() async {
    Map<Permission, PermissionStatus> statuses = await [
      Permission.storage,
      Permission.manageExternalStorage,
      Permission.accessMediaLocation
    ].request();

3

Answers


  1. You need these permissions for Android 13:

    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
    
    Login or Signup to reply.
  2. On an Android 13 device you will not ask for permission READ_EXTERNAL_STORAGE.

    You have it automatically for files created by your app.

    Login or Signup to reply.
  3. Use this approach with permission handler https://pub.dev/packages/permission_handler :

    var permissionStatus = await Permission.storage.status;
    
            switch (permissionStatus) {
              case PermissionStatus.denied:
              case PermissionStatus.permanentlyDenied:
                await Permission.storage.request();
                break;
              default:
            }
    

    In manifest only :

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search