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

[Android]READ_EXTERNAL_STORAGE permission #1473

Closed
angcyo opened this issue Mar 24, 2024 · 7 comments
Closed

[Android]READ_EXTERNAL_STORAGE permission #1473

angcyo opened this issue Mar 24, 2024 · 7 comments
Labels
stale suggestion New feature or request

Comments

@angcyo
Copy link

angcyo commented Mar 24, 2024

Instead of using
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),

use
context.getExternalCacheDir()

so we don't need Manifest.permission.READ_EXTERNAL_STORAGE.

@angcyo angcyo added the suggestion New feature or request label Mar 24, 2024
@Levi-Lesches
Copy link

Levi-Lesches commented Mar 27, 2024

Hi, I think this is related to my error:

 Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Pictures/Screenshots/Screenshot_20240326-210404.png: open failed: EACCES (Permission denied)

Which crashed my app.

If this will fix the issue, I think it should be added, or at least documented that permissions are required.

@angcyo
Copy link
Author

angcyo commented Mar 28, 2024

You need permission to read sd files directly,

but the images returned from the system album are automatically cached in the app cache directory,

so you do not need permission to read images.

@Levi-Lesches
Copy link

Right. Turns out, as of Android API 33, we need to explicitly ask for permissions in the AndroidManifest.xml:

    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>

and in Dart:

import "package:permission_handler/permission_handler.dart";

if (await Permission.photos.request().isGranted) {
  // ...
}

@angcyo
Copy link
Author

angcyo commented Mar 30, 2024

have fun.

@SoftWyer
Copy link

The use of Environment.getExternalStoragePublicDirectory will crash on older devices (definitely Android 28 Pie) if the compileSdkVersion=34 and/or targetSdkVersion=33

Copy link

github-actions bot commented Apr 7, 2024

This issue is stale because it has been open for 7 days with no activity.

@github-actions github-actions bot added the stale label Apr 7, 2024
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale suggestion New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants