I am trying to read a file from the download folder on Android Q by doing this:
File downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File f = new File(downloadDir, "some-existing-file");
if(!f.exists()) {
throw new IllegalStateException();
}
Uri furi = Uri.fromFile(f);
try {
ParcelFileDescriptor des = getContentResolver().openFileDescriptor(
furi, "r", null);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
I also set android:requestLegacyExternalStorage="true"
in the manifest, and requested WRITE_EXTERNAL_STORAGE
and READ_EXTERNAL_STORAGE
runtime permissions.
The file exists but when trying to open the file descriptor, an exception arises:
java.io.FileNotFoundException: open failed: EACCES (Permission denied)
.
I read the changes made in Android Q storage, but could not figure out how can I just read the file without having user interaction.
Thanks!