Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open_file requires MANAGE_EXTERNAL_STORAGE which is considered Dangerous #265

Open
feykro opened this issue Sep 14, 2023 · 6 comments
Open

Comments

@feykro
Copy link

feykro commented Sep 14, 2023

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.

@aju-annaseem
Copy link

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

@feykro
Copy link
Author

feykro commented Sep 14, 2023

@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 feykro changed the title open_file requires MANAGE_EXTERNAL_STORAGE which is way to high open_file requires MANAGE_EXTERNAL_STORAGE which is considered Dangerous Sep 14, 2023
@Charlinjoeaht
Copy link

I am facing the same issue too

@Charlinjoeaht
Copy link

Charlinjoeaht commented Sep 22, 2023

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
Copy link

any update on this

@feykro
Copy link
Author

feykro commented Jun 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants