I wasn't facing this issue in Android 9 and in Android 10 i opted out for Legacy Storage. But in Android 11, I am not able to open the file downloaded from Download Manager. The same file can be opened from file Manager, though.
Also, I checked the owner of that file, it is showing com.android.providers.downloads and not my app.
I am also creating a pdf file in Document/myfolder directory, and it can be easily openable using intent and there my app is the owner of that file.
Also, if I am saving the downloaded file to Document/myfolder directory, it still can't be opened using that intent.
As per my understanding, from Android 11, they introduced scope storage, and if the owner of that file is accessing it. It will allow to read/write through READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permission.
For both the file, I am using the same Intent.
Anyone has idea how to change the owner of my downloaded file so that i can gain open or what is the exact reason i am not able to open that downloaded file?
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, PDF_TYPE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Here PDF_TYPE is correct and uri is also correct.
DownloadManager code is also correct here a small snippet
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, subPath.getPath());
I am having the same issue, but in Android 10.
This works for me in Android 11