Permission to read excel file in shared DOCUMENTS folder always denied, after Upgrading to API 33

173 views Asked by At

Okay, I know there are a lot of similar threads regarding this issue but I haven't found one which can solve my issue yet. I have been struggling with this issue for days.

A bit of the background, my apps will read & write and excel file called "data.xlsx" which will be stored in Documents/GRC folder. Full path to this directory is as follows:

val ourAppFileDirectory =
        File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "GRC")

On API 32 my application works just fine, but starting on API 33 it will treat my MANAGE_EXTERNAL_DIRECTORY permission as fully denied and I can't even enable it from settings.

I tried to log my apps, and it seems like it can detect that the file exists just fine, but it cannot read it at all.

val excelFile = File(ourAppFileDirectory, "data.xlsx")
Log.d("Check Existence", excelFile.exists().toString())
Log.d("Check Readability", excelFile.canRead().toString())
return !excelFile.exists()

Below is the output from the logcat: EACCESS: (Permission Denied)

I understand that in API 33 there're changes in behavior so that we need to use either READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, or READ_MEDIA_AUDIO. But there are no new permissions for reading document type of data.

My apps seems to be able to create excel file within the app "internally" just fine. Only problem is when I want to read "foreign" excel file. Does anybody know the workaround to this issue, or any substitute for MANAGE_EXTERNAL_STORAGE permission in API 33?

Thank you in advance.

2

There are 2 answers

0
Mubeen Riaz On

i had the same issue. I used ACTION_OPEN_DOCUMENT in intent and onActivityResult i saved the original copy of the file to the app's internal storage using input stream. Now i can do whatever i want with the copy of the file because its inside my app's storage. You don't need any permission for this solution.

0
Anggrayudi H On

java.io.File is almost deprecated now, since accessing files in scoped storage is restricted via URI. You have to use Storage Access Framework (SAF) to resolve the issue. I have a library that ease and simplify SAF's usage, i.e. SimpleStorage