Access denied #116

Closed
opened 2026-04-24 23:08:03 +02:00 by adam · 7 comments
Owner

Originally created by @skyzuma on GitHub (Apr 30, 2022).

Steps to reproduce

  1. open mobile app
  2. select "local media"
  3. select a type
  4. click "new Folder"
  5. select an folder > Error: Access Denied"

Expected behaviour

  • Tell us what should happen
  • like on a sm-t725
    • select "local media" > select a type > click "new Folder" > create a new one or use an existing one (ive created a new one) > select this folder > android ask for permission > grant permission > folder permission success & folder used > go back an see the folder(s)

Actual behaviour

  • Tell us what happens
    • select "local media" > select a type > click "new Folder" > select or create an folder > Error Access Denied

Environment data

Audiobookshelf Version: 0.9.43-beta

  • Android App?
  • iOS App?

Android Issue

Android version: 9

Device model: Huawei P 10

Stock or customized system: Stock

Originally created by @skyzuma on GitHub (Apr 30, 2022). ### Steps to reproduce 1. open mobile app 2. select "local media" 3. select a type 4. click "new Folder" 5. select an folder > Error: Access Denied" ### Expected behaviour - Tell us what should happen - like on a sm-t725 - select "local media" > select a type > click "new Folder" > create a new one or use an existing one (ive created a new one) > select this folder > android ask for permission > grant permission > folder permission success & folder used > go back an see the folder(s) ### Actual behaviour - Tell us what happens - select "local media" > select a type > click "new Folder" > select or create an folder > Error Access Denied ### Environment data Audiobookshelf Version: 0.9.43-beta - [x] Android App? - [ ] iOS App? #### Android Issue Android version: 9 Device model: Huawei P 10 Stock or customized system: Stock
adam added the bug label 2026-04-24 23:08:03 +02:00
adam closed this issue 2026-04-24 23:08:03 +02:00
Author
Owner

@hobesman commented on GitHub (May 16, 2022):

Is this using the SD card or local folder, or does it not even get that far?

On my phone I had to go into system settings on the phone and manage permissions, then disable and reenable storage permissions for the app. This makes it possible to add a local folder on the internal storage. Still can't get it to set a folder on the SD card.

@hobesman commented on GitHub (May 16, 2022): Is this using the SD card or local folder, or does it not even get that far? On my phone I had to go into system settings on the phone and manage permissions, then disable and reenable storage permissions for the app. This makes it possible to add a local folder on the internal storage. Still can't get it to set a folder on the SD card.
Author
Owner

@skyzuma commented on GitHub (May 16, 2022):

0.9.45-beta

on the local i can now create and choose this folder BUT only on the folder "download" ... i cant choose any other local place ... still no way on sd-card ...

@skyzuma commented on GitHub (May 16, 2022): 0.9.45-beta on the local i can now create and choose this folder BUT only on the folder "download" ... i cant choose any other local place ... still no way on sd-card ...
Author
Owner

@zblesk commented on GitHub (Jun 13, 2022):

0.9.49-beta

Tried the above things, like using the Downloads folder or removing and re-adding storage permission.
All the time, the behavior is the same: I am able to create a new folder and select it. Then I get a popup asking "Allow audiobookshelf to access files in ?"
I click Allow, then get the red popup saying Error: access denied, and no media folder is added.

@zblesk commented on GitHub (Jun 13, 2022): 0.9.49-beta Tried the above things, like using the Downloads folder or removing and re-adding storage permission. All the time, the behavior is the same: I am able to create a new folder and select it. Then I get a popup asking "Allow audiobookshelf to access files in <folder name>?" I click Allow, then get the red popup saying Error: access denied, and no media folder is added.
Author
Owner

@Jnewbon commented on GitHub (Jul 9, 2022):

I'm on Android 10

So after spending a few hours picking through the code and android docs, i found an odd workaround for giving the app access to a folder on the SD card You need to select the root of the SD card first before creating a folder on the card.

Click New Folder
Navigate to the Root of the SD card
Allow Access (Will add the root of the SD card as a folder to the app)
Click add New Folder again
Navigate to the actual folder you want to store stuff in on the SD card
Click allow Access

After that you can removed the Root SD card from the app and keep the Subfolder.

What tipped me off to this was replacing the following code
https://github.com/advplyr/audiobookshelf-app/blob/cb2aaede67b9e5480c818fab15918f9dd5a96bd8/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsFileSystem.kt#L85-L90

with

override fun onStorageAccessDenied(requestCode: Int, folder: DocumentFile?, storageType: StorageType) {
  if (requestCode == 6) {
    Log.d(TAG, "STORAGE ACCESS DENIED $requestCode")
    mainActivity.storageHelper.requestStorageAccess(7, storageType)
  } else {
    Log.d(TAG, "STORAGE ACCESS DENIED TWICE $requestCode")
    var jsobj = JSObject()
    jsobj.put("error", "Access Denied")
    call.resolve(jsobj)
  }
}

This went through the folder selection, popped up another dialog at the SD Cards root which I clicked allow to, but didn't then create the folder, I had to click new folder again and click the location I wanted again and this second time it was successful.

Only tested this on API 29 i know API 30 need a different style of storage but hope this helps

@Jnewbon commented on GitHub (Jul 9, 2022): I'm on Android 10 So after spending a few hours picking through the code and android docs, i found an odd workaround for giving the app access to a folder on the SD card You need to select the root of the SD card first before creating a folder on the card. Click New Folder Navigate to the Root of the SD card Allow Access (Will add the root of the SD card as a folder to the app) Click add New Folder again Navigate to the actual folder you want to store stuff in on the SD card Click allow Access After that you can removed the Root SD card from the app and keep the Subfolder. What tipped me off to this was replacing the following code https://github.com/advplyr/audiobookshelf-app/blob/cb2aaede67b9e5480c818fab15918f9dd5a96bd8/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsFileSystem.kt#L85-L90 with ```kotlin override fun onStorageAccessDenied(requestCode: Int, folder: DocumentFile?, storageType: StorageType) { if (requestCode == 6) { Log.d(TAG, "STORAGE ACCESS DENIED $requestCode") mainActivity.storageHelper.requestStorageAccess(7, storageType) } else { Log.d(TAG, "STORAGE ACCESS DENIED TWICE $requestCode") var jsobj = JSObject() jsobj.put("error", "Access Denied") call.resolve(jsobj) } } ``` This went through the folder selection, popped up another dialog at the SD Cards root which I clicked allow to, but didn't then create the folder, I had to click new folder again and click the location I wanted again and this second time it was successful. Only tested this on API 29 i know API 30 need a different style of storage but hope this helps
Author
Owner

@advplyr commented on GitHub (Jul 9, 2022):

@Jnewbon That workaround was mentioned in another thread and in discord but I never actually reproduced the issue.

Your solution wouldn't work if someone selected a folder 2 levels deep on their SD card right?
We could continually increment the request code but then their maybe an infinite loop I'm not sure.

Do you have an idea on how to solve for this for good?

@advplyr commented on GitHub (Jul 9, 2022): @Jnewbon That workaround was mentioned in another thread and in discord but I never actually reproduced the issue. Your solution wouldn't work if someone selected a folder 2 levels deep on their SD card right? We could continually increment the request code but then their maybe an infinite loop I'm not sure. Do you have an idea on how to solve for this for good?
Author
Owner

@zblesk commented on GitHub (Jul 9, 2022):

Not sure if it makes any difference, but I'm encountering this error with phone's storage. I don't even have an SD card.
I'm hoping for a fix, because this is preventing me from switching to Audiobookshelf. :(

@zblesk commented on GitHub (Jul 9, 2022): Not sure if it makes any difference, but I'm encountering this error with phone's storage. I don't even have an SD card. I'm hoping for a fix, because this is preventing me from switching to Audiobookshelf. :(
Author
Owner

@Jnewbon commented on GitHub (Jul 11, 2022):

So i took some time looking at the docs and the plugin and have created #278
Only tested this on Android 10, so not sure how it will act with 9 or 11

@Jnewbon commented on GitHub (Jul 11, 2022): So i took some time looking at the docs and the plugin and have created #278 Only tested this on Android 10, so not sure how it will act with 9 or 11
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf-app#116