on Android R i'm fine to write file in Download folder. If i try to read file i get IOException access denied.
zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(Environment.getExternalStorageDirectory().getAbsolutePath()
"/Download/saves.zip")));
What is the right way to read file on Android R or from what folder can i read without problem?
I'm using
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
android:requestLegacyExternalStorage=”true”
EDIT: New Code
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.Downloads.DISPLAY_NAME, "saves.zip");
contentValues.put(MediaStore.Downloads.MIME_TYPE, "application/zip");
Uri uri = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
uri = MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL);
}
Uri itemUri = getContentResolver().insert(uri, contentValues);
zis = new ZipInputStream(getContentResolver().openInputStream(itemUri));
CodePudding user response:
Starting in Android 11, apps that use the scoped storage model can access only their own app-specific cache files.
So better use app's shared data folder to write/read your files.
here is the full description.
https://developer.android.com/about/versions/11/privacy/storage#permissions-target-11
CodePudding user response:
on Android R i'm fine to write file in Download folder.
If your app can write a file somewhere than it can certainly read that file.
Your problem does not make sense.
Is there anything you did not tell?