Access denied writing files on USB

Hello,

Unity Editor version: 3.10.0
ML2 OS version: 1.11.0
Unity SDK version: 2022.3.9
Host OS: Windows

I’m developing a Unity app for Magic Leap 2 and encountering write permission issues when trying to create a folder on a connected USB drive. It seems the USB is mounted as internal storage, but I’m getting ‘access denied’ errors. I’ve already modified the AndroidManifest.xml to include READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions (even if USB is under /storage/XXXX-XXXX), and adjusted the Player Settings in Unity. Has anyone else experienced this, and are there specific APIs or workarounds recommended for writing to USB drives in this configuration?

I can read and copy files from the USB device…

Many thanks :grinning_face:

It sounds like you’re running into Android’s scoped storage restrictions, which got stricter starting from Android 10. Even if your USB drive mounts under /storage/XXXX-XXXX, Android often treats it as external storage, meaning standard permissions alone (READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE) aren’t enough.

I’d recommend looking at this repo UnitySimpleFileBrowser —it uses Storage Access Framework which should resolve the ‘access denied’ error you’re facing.

I’ll give it a try, thanks!

Edit: Even using UnitySimpleFileBrowser and its handlers, it still gives me permission denied

We use the standard Android 10 storage access so the only thing I can think of is that something with the API or Storage Access Frame work is not configured correctly. Note that even when using SAF you won’t be able to use a traditional file path like /storage/xxx-xxx Instead you will need to use the URI (the path returned by the system)

You may be able to access / create directories with SAF by adding android:requestLegacyExternalStorage="true" to your manifest.