Read_External_Storage Permission for Android

READ_EXTERNAL_STORAGE permission for Android

You have two solutions for your problem. The quick one is to lower targetApi to 22 (build.gradle file).
Second is to use new and wonderful ask-for-permission model:

if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if (shouldShowRequestPermissionRationale(
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Explain to the user why we need to read the contacts
}

requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);

// MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE is an
// app-defined int constant that should be quite unique

return;
}

Sniplet found here: https://developer.android.com/training/permissions/requesting.html

Solutions 2: If it does not work try this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
REQUEST_PERMISSION);

return;

}

and then in callback

@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSION) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission granted.
} else {
// User refused to grant permission.
}
}
}

that is from comments. thanks

READ_EXTERNAL_STORAGE doesn't work on Android 10


This code only works if you add requestLegacyExternalStorage to the manifest.

So, add android:requestLegacyExternalStorage="true" to the <application> element in the manifest.

Then everything works fine at once , but this attribute disappear in Android 11

In Android 11+, to a large extent, READ_EXTERNAL_STORAGE works as it did in Android 9 and below. There will be some more areas that are off-limits, though.

What Google would prefer that you do is to stop thinking in terms of files and the filesystem, and instead use the Storage Access Framework (e.g., ACTION_OPEN_DOCUMENT).

Remove WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions from Android Project

@Sergey Comment: They can be merged from the dependent library. You can check if any library you are using have those permissions in their Manifest file.

I looked into it and found this article How Libraries can silently add permissions to your Android App and the Fix. It Worked.

But I'm using camera, and I was storing these pictures in the Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData). Which requires WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions.

So, I replace the path with FileSystem.CacheDirectory and it worked (Intenral Storage doesn't requires Read and Write Permissions in Manifest file).

READ_EXTERNAL_STORAGE shows permission but not READ_EXTERNAL_STORAGE

I fixed by adding tools:remove="android:maxSdkVersion" like this:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"/>

READ_EXTERNAL_STORAGE permission not asking for permission

First, no need to check for individual permissions...you can check multiple permissions together.

Check for multiple permissions

By this way it will solve your problem too



Related Topics



Leave a reply



Submit