18
2019
Read File from Oculus Quest /sdcard/ Folder
New 2023 (more limitations)
“This is because the Quest OS v53 now uses Android 12, which limits the way apps can access storage. From the developers of Polysketch:
– No Access
— /sdcard/Polysketch/
– Can create folders, but not files
— /sdcard/Android/Polysketch/
– Full folder & file creation
— /sdcard/Android/Android/data/com.PolysketchLLC.Polysketch/files (Application.persistentDataPath)
— /sdcard/Download/Polysketch/ —– not very safe as users will arbitrarily delete-all here if running out of space
— /sdcard/Documents/Polysketch/ —– seems like the best option. Easy user access, and we can read each other’s save locations if we wish to.
How to update –
Setting the flag preserveLegacyExternalStorage to true in the manifest will allow you to read & write from sdcard/whatever/ if the app is installed as an update to an older version. On clean installs, this flag is ignored. So this flag won’t grant us access indefinitely, but will let us read old save files and move them to the new preferred spot. AndroidManifest.xml <application android:requestLegacyExternalStorage=”true” android:PreserveLegacyExternalStorage=”true”>
Solution#1:
– Place your file into some sdcard folder (by browsing there with Explorer), for example:”This PC\Quest\Internal shared storage\Download\myfile.txt”
– Add script to load file:var t = File.ReadAllText("/sdcard/Download/myfile.txt");
– From Unity menu select: Oculus/Tools/Create store-compatible AndroidManifest.xml
– Modify Assets/Plugin/Android/AndroidManifest.xml, add this line after </application> :<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
– Build & Run *Note: run fails, due to missing launch action.. so run the app manually in device (from library/unknown sources)
– Allow Read permissions when you start the app
Optional:
– You can enable LAUNCHER, to make Build & Run work, by replacing this line:<category android:name="android.intent.category.INFO"
/>
with:<category android:name="android.intent.category.LAUNCHER"/>
– Can also disable permission request (while doing tests), by modifying this line:meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="false"
into:meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true"
– Can also add Write permissions:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
My AndroidManifest.xml:
https://gist.github.com/unitycoder/a8a827311ea0837b06af6ccde85effec
Solution#2: (temporary fix)
check what permissions the app has:adb shell dumpsys package <package_name>
then add permissionsadb shell pm grant <package_name> android.permission.READ_EXTERNAL_STORAGE
adb shell pm grant <package_name> android.permission.WRITE_EXTERNAL_STORAGE
Resources:
– https://developer.oculus.com/distribute/latest/concepts/publish-mobile-manifest/
– https://forums.oculusvr.com/developer/discussion/78412/accessing-local-files
Related Posts
10 Comments + Add Comment
Leave a comment
Recent posts
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
Recent Comments
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- ffmpeg stream raw video into Unity Texture2D on
Hasn’t worked for me.
I followed the instructions closely, replaced the manifest file with the example provided. I built and run, and then closed the app and opened it from ‘Unknown sources’. I believe it throws an error when running the line
string testLoadString = File.ReadAllText(“/sdcard/Download/test.txt”);
Although I don’t know how to see the error once it is not in Unity. Note that, even when I had not included the line
meta-data android:name=”unityplayer.SkipPermissionsDialog” android:value=”true”
it still didn’t ask for permissions when running the app.
Any help would be greatly appreciated.
tested it, and seems like using “Write Permission to External” in build settings helped!
Also you need to get that permission dialog to appear, otherwise it didnt work. (not sure if it appeared when running from library – instead of build and run, or if my new AndroidManifest.xml helper, i’ve added it to that previous link)
This worked perfectly on Quest 1, BUT not on Quest 2.
Any idea if the path changed on Quest 2?
Can pay 50$ via paypal for any insight leading to the solution 🙂
Thanks
Felix
i’m interested also, waiting for quest 2 to arrive.. maybe in the next few weeks can test too.
is there sdcard folder if you browse device from windows? (thats from where i checked it last time)
works now, see the comment / link for @3dskild
Any news on if Quest 2 directory has changed? On if there are any new steps involved.
looks like others having problems too.
adding this for reference, https://forums.oculusvr.com/developer/discussion/94022/quest-2-local-storage-path-changed-quest1-app-broken
i didn’t get my quest2 yet so cannot test that adb shell command either..
I had video file read problems in 2019.1 and it seems to be an Android 10 bug.
It was solved for me by using Unity 2019.2.
https://issuetracker.unity3d.com/issues/android-video-player-cannot-play-files-located-in-the-persistent-data-directory-on-android-10?_ga=2.2188601.882680562.1607255200-1472655325.1605534586
nice! works in Quest 2 if select: Android 9 (API 28) *i’m using 2018.4.8f1
https://forums.oculusvr.com/developer/discussion/comment/779570/#Comment_779570
possible manifest fix:
https://forum.unity.com/threads/android-10-and-scoped-storage-missed-features-in-unity-2019.749333/#post-5095214