0

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.

Milanor
  • 257
  • 1
  • 2
  • 10
  • 1
    "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" -- that means your app did not create the file. You can only read/write files in `Documents` that your app created. "Only problem is when I want to read "foreign" excel file" -- let your user choose the Excel content via `ACTION_OPEN_DOCUMENT` / `ActivityResultContracts.OpenDocument`. – CommonsWare Aug 08 '23 at 10:41

1 Answers1

0

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.