Application.persistentdatapath points to sdcard while write permission is set to internal

I get thousands of UnauthorizedAccessExceptions in my Game Performance dashboard followed up by bug reports from angry gamers who can’t save.

Those 3 exceptions make up the bulk:
UnauthorizedAccessException: Access to the path “/storage/sdcard1/Android/data/com…files/savedGames.gd” is denied.
UnauthorizedAccessException: Access to the path “/mnt/internal_sd/Android/data/com…/files/savedGames.gd” is denied.
UnauthorizedAccessException: Access to the path “/mnt/sdcard/Android/data/com…/files/savedGames.gd” is denied.

My settings are:
Install location: Automatic
Write Permission: Internal
…and I’m using Application.persistentdatapath.

I guess this could easily be fixed by giving the game permissions to write on a sd card but that’s something I would like to avoid because of how scary those permissions look to some users.

Any idea how I can work myself around this? Is this a Unity bug? Or am I missing something? Can I force Application.persistentdatapath to give me a “internal” path?

1 Like

I have this Problem too at the moment. Testing on a new Device without sdcard - removed write permission in all android manifest files and set settings to internal … persistentDataPath still shows sdcard and throws error when writing - i tried alot other Vars but can’t find the right one.

Did you made any progress?

Sadly no. I asked around in different dev communities and the only thing I got out of it was that in a lot of cases a simple device restart could fix it but that’s difficult to communicate and doesn’t make a good user experience.

Let me know if you find something

It’s late but the bit of code in the answer by Clas of this post seem to be what you are looking for (don’t look at the “best answer”)

1 Like