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: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> Here is the core bits of code I've tried Code (CSharp): writer = new StreamWriter($"/mnt.sdcard/VirtualRoomSwayData/Participant.csv"); Code (CSharp): writer = new StreamWriter("/storage/extSdCard/VirtualRoomSwayData/Participant.csv"); Code (CSharp): 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: Code (CSharp): 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.
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
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? https://answers.unity.com/questions/492681/how-to-use-adb-logcat.html#answer-571021 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.
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?
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.
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"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:compileSdkVersion="29" android:compileSdkVersionCodename="10" android:installLocation="auto" package="REDACTED" platformBuildVersionCode="29" platformBuildVersionName="10"> <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true"/> <uses-feature android:glEsVersion="0x00030000"/> <supports-gl-texture android:name="GL_KHR_texture_compression_astc_ldr"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/> <uses-feature android:name="android.hardware.microphone" android:required="false"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-feature android:name="android.hardware.touchscreen" android:required="false"/> <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false"/> <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false"/> <uses-feature android:name="android.hardware.vr.headtracking" android:required="true" android:version="1"/> <uses-feature android:name="oculus.software.handtracking" android:required="false"/> <uses-permission android:name="com.oculus.permission.HAND_TRACKING"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <application android:allowBackup="false" android:extractNativeLibs="true" android:icon="@Mipmap/app_icon" android:label="@String/app_name" android:networkSecurityConfig="@XML/network_sec_config" android:requestLegacyExternalStorage="true"> <activity android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenLayout|screenSize|uiMode" android:hardwareAccelerated="false" android:launchMode="singleTask" android:name="com.unity3d.player.UnityPlayerActivity" android:screenOrientation="landscape" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> <category android:name="com.oculus.intent.category.VR"/> </intent-filter> <meta-data android:name="unityplayer.UnityActivity" android:value="true"/> <meta-data android:name="android.notch_support" android:value="true"/> <meta-data android:name="com.oculus.vr.focusaware" android:value="true"/> <meta-data android:name="android.notch_support" android:value="true"/> </activity> <meta-data android:name="unity.splash-mode" android:value="0"/> <meta-data android:name="unity.splash-enable" android:value="true"/> <meta-data android:name="notch.config" android:value="portrait|landscape"/> <meta-data android:name="unity.build-id" android:value="f9d86e1d-da2b-4f34-ac63-2b099cfad14d"/> <meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/> <meta-data android:name="com.unity.xr.oculus.LowOverheadMode" android:value="false"/> <meta-data android:name="com.oculus.supportedDevices" android:value="quest|quest2"/> <meta-data android:name="com.oculus.handtracking.frequency" android:value="LOW"/> </application> </manifest>
Awesome! Thanks! Worked for me as well. The only settings I needed were: Write Permission External (SDCard) <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> and android:requestLegacyExternalStorage="true" in the <application> tag
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
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 <once it recognized the device> adb shell <to be able to execute command inside my device> 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.
Hello! I've been at a dead end with trying to write files from the apk file of my game that I have installed on my Quest 2. The game targets Android 13, so permissions like writing external storage are more restricted compared to when this thread was last updated. I haven't had any success with Application.persistentDataPath paired with public folder directories like Documents that should be accessible. Write Permission External is enabled in Player Settings in Unity, and Storage Permissions are enabled for my app and SideQuest, which is what I used to install the apk. Any insights would be greatly appreciated.