Writing files to Oculus Quest

Heya all,
I’m trying to write a .csv file and folder to the Quest2 headset so I can access it on the storage of the headset. I’ve been trying several methods I’ve found online without success. There seems to be several ways of targeting the storage none of which I’ve managed success with.

It might be permissions. Some articles have mentioned it should pop up a access dialogue for the user (but I think that may be for reading rather than writing) which my app definitely doesn’t.
Project Settings > Player > Other > Write Permissions: External (SDCard)
The UnityManifest file has:

Here is the core bits of code I’ve tried

writer = new StreamWriter($"/mnt.sdcard/VirtualRoomSwayData/Participant.csv");
writer = new StreamWriter("/storage/extSdCard/VirtualRoomSwayData/Participant.csv");
writer = new StreamWriter("/storage/emulated/0/VirtualRoomSwayData/Participant.csv");

Any help greatly appreciated

Don’t use absolute paths (on any platform). Use the Application.persistentDataPath, like so:

                string fname = System.DateTime.Now.ToString("HH-mm-ss") + ".csv";
                string path = Path.Combine(Application.persistentDataPath, fname);
                file = new StreamWriter(path);

Thanks JoeStrout. I just tried your code and also no file has been written. I tried with Permissions set to Internal and External SD Card, resetting the USB connection and restarting application from the headset (as I’ve read that can fix some things). Still nothing was written. Any other ideas?

No. I use that exact code all the time, and it works for me. Did you get an exception? Or could it be you just can’t find the file (i.e. looking in the wrong place)?

I’ve found that the Windows explorer sometimes displays stale data. (Deleted files were still shown, or created files were not shown even when they were there.) Replugging the headset usually fixes it, but that definitely caused me some unnecessary minutes of head-sratching before. Not sure whether that’s the issue here though.

1 Like

No exceptions or errors just no file. I’ve looked both at the “internal” path and in the external locations and there are definitely no files ever written.
I want to write files to a folder on the Quest 2 when it is plugged in which is the SD Card from my understanding. I can’t even create a new directory there.
I’ve also checked Android>data>“apk build folder”>files

Yes I read that as well. I always replug before I check for the files in case that is the issue.

I don’t think being plugged in has anything to do with it. The files will appear in /sdcard/Android/data/your-app-id.

If they’re not there, and you’re not getting any exceptions, then I’m afraid I have no idea why it’s not working for you.

Thanks anyhow JoeStrout. I’m at a loss why it refuses to work.
I’ve created a custom Android manifest file now but that hasn’t solved anything.

what does logcat show?

pretty sure that saving data into download solder worked with regular file io, using path:
“/sdcard/Download/”

also there used to be one bug on reading files, it was fixed by using “Android 9 (API 28)”, instead of 10… cant remember if it affected writing.

1 Like

Maybe we misunderstood. The solution given before works when executed in an app on-device.
Are you’re trying to write files to the Quest from the Unity Editor or a Windows application?

1 Like

I think I’m going to have to work out how to look into the logs. I was hoping it was a simple fix but seems to not be.

No it is just the apk application writing a directory and file is all I’m after

Did anyone manage to fix this issue?

I have tried both paths:
/sdcard/Download/
/storage/emulated/0/

with internal, then external permissions set within player settings, plus an android manifest with read and write access to external and it still says that “access denied” when i try to read from the quest 2.

Any suggestions?

THAT WAS IT, the Android 9 fixed the issue for me.
In case someone else has the same issue:
Select Android Pie 9
Internal Access Require
Write Permission External (SDCard)

AndroidManifest:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
5 Likes

Awesome! Thanks! Worked for me as well.

The only settings I needed were:
Write Permission External (SDCard)

and

android:requestLegacyExternalStorage=“true” in the tag

5 Likes

Yeah I can also confirm this works. It’s weird because from what I remember it used to work just by setting Write Permission External (SDCard) from Editor, but apparently now you have to also add the permission manually to manifest

1 Like

This worked for me. Thanks.

1 Like

Thanks! solved my issue as well!

1 Like

None of the proposals in this thread to access the folders inside the /sdcard directory worked for me, the only thing that worked for me is access to persistent data but only in that directory, I can’t access Pictures or Movies directories.
The only way I could do to grant read permissions to the /sdcard directory and subdirectories to my application is by manually granting the permission as follows:

adb devices

adb shell

pm grant <com.company.proyectName> android.permission.READ_EXTERNAL_STORAGE
<understanding that “com.company.projectName” is the name of the application / package**>**

If you don’t know the package name of your application you can do the following to get a list of all installed applications / packages:
pm list packages
Maybe it will help someone else.