简体   繁体   中英

Read file in internal Download folder Android R

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));

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM