skip to Main Content

So I was using the open_file library to open some pdf files. When I switched from cache storage to app’s local document folder storage using getApplicationDocumentsDirectory(), the files were not opening. Using

var result = await OpenFile.open(filePath);
print(result.message);

return Permission denied: android.permission.MANAGE_EXTERNAL_STORAGE

My filePath is in the format /data/user/0/com.example.<app name>/app_flutter/New-Note-2024-09-19-00-02-48.pdf

It is a bit strange that I need permission to access my app’s local storage

Nevertheless I included

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

    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
    
    <application
     ....
</manifest>

In my AndroidManifest.xml, and here is my flutter code for requesting permissions:

   Future<void> requestStoragePermission() async {
      if (await Permission.storage.request().isGranted) {
        // Permission granted
      } else {
          openAppSettings();
        // Handle permission denied
        print("Storage permission denied");
      }
    }

However it defaults automatically to "Permission denied" without me even doing anything.

And if I go to app settings, it shows "No permissions requested" and outputs No permissions found in manifest for: []15.

I even tried including READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE on my manifest, still doesn’t work.

2

Answers


  1. Chosen as BEST ANSWER

    I finally found my solution, the issue was using getApplicationDocumentsDirectory(), should've used getExternalStorageDirectory().

    This should've occurred to me naturally as by using application's local documents directory to save files I was trying to access my App's local files from another external app when running Openfile.open(), which would have not worked. Just like how you can't browse an app's local directory from a File Manager (unless rooted).


  2. Storage Permission in Android Before 13 and After 13 are changed.

    You provide different way in both case while asking for storage permission.

    I was already give detailing answer with code.

    You can see HERE storage permission solution

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search