open_file icon indicating copy to clipboard operation
open_file copied to clipboard

open_file requires MANAGE_EXTERNAL_STORAGE which is considered Dangerous

Open feykro opened this issue 2 years ago • 6 comments

Hello,

As of Android api 33, the READ_STORAGE and WRITE_STORAGE autorisations have been depreciated. The Google PlayStore now requires app to target API 33 so this change must be addressed by all apps targetting production releases.

Issue Running OpenFile.open fails on API 33. The new permission required by open_file is "MANAGE_EXTERNAL_STORAGE". The problem with that permission is that it's very powerful and considered dangerous by Google themselves. Users who want to submit an app to the Google PlayStore require a special autorisation to use it, and they need to fill a security form. That special application will be rejected if the permission is not required for the app to run in the first place, which is not the case of most apps.

Solving the issue for no-prod Using the package Permission_handleer, you need to ask permission to manage user's storage, here's the code:

Future<bool> requestStoragePermissions() async {
    var permission = await Permission.manageExternalStorage.status;

    if (permission != PermissionStatus.granted) {
      await Permission.manageExternalStorage.request();
      permission = await Permission.manageExternalStorage.status;
    }
    return permission == PermissionStatus.granted;
  }

When this returns true, you may try to run OpenFile.open and it will be fine.

Solving the issue for prod I do not have an answer for this pakcage, hence why I raise this issue. The obvious solution would be that the package uses a lower permission or a workaround to open the file without using such a dangerous and highly regulated permission.

In the meanwhile, replace open_file by a fork of it, open_filex: https://pub.dev/packages/open_filex Your need to straight out replace the package in the pubspec.yaml, but the calls are the same.

feykro avatar Sep 14 '23 12:09 feykro

i want to upload my app to the Play Store. what do I do?

aju-annaseem avatar Sep 14 '23 12:09 aju-annaseem

@aju-annaseem You need to remove MANAGE_EXTERNAL_STORAGE from your AndroidManifest, as well as the outdated permissions (read more here). You also need to target API 33. For that, I suggest you replace open_file with open_filex which I linked in the original post.

feykro avatar Sep 14 '23 13:09 feykro

I am facing the same issue too

Charlinjoeaht avatar Sep 18 '23 19:09 Charlinjoeaht

I am facing this issue while trying to open the pdf file.

Do we need to implement anything more from the following part?

Open a file Your app might use documents as the unit of storage in which users enter data that they might want to share with peers or import into other documents. Several examples include a user opening a productivity document or opening a book that's saved as an EPUB file.

In these cases, allow the user to choose the file to open by invoking the ACTION_OPEN_DOCUMENT intent, which opens the system's file picker app. To show only the types of files that your app supports, specify a MIME type. Also, you can optionally specify the URI of the file that the file picker should display when it first loads by using the EXTRA_INITIAL_URI intent extra.

The following code snippet shows how to create and invoke the intent for opening a PDF document:

// Request code for selecting a PDF document.
private static final int PICK_PDF_FILE = 2;

private void openFile(Uri pickerInitialUri) {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("application/pdf");

    // Optionally, specify a URI for the file that should appear in the
    // system file picker when it loads.
    intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri);

    startActivityForResult(intent, PICK_PDF_FILE);
}

Reference: https://developer.android.com/training/data-storage/shared/documents-files#open-file

Charlinjoeaht avatar Sep 22 '23 21:09 Charlinjoeaht

any update on this

Charlinjoeaht avatar Oct 09 '23 07:10 Charlinjoeaht

@Charlinjoeaht use open_fileX instead of open_file: https://pub.dev/packages/open_filex

feykro avatar Jun 11 '24 07:06 feykro