Aug
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”>

Source:
https://forum.unity.com/threads/access-to-oculus-2-local-video-images-from-unity.1434886/#post-9004114

:p


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

My Build Settings for Install location and Write Permissions (they don’t seem to affect much?)
*UPDATE: Settings Write Permission to External seems to help!

Solution#2: (temporary fix)

check what permissions the app has:
adb shell dumpsys package <package_name>
then add permissions
adb shell pm grant <package_name> android.permission.READ_EXTERNAL_STORAGE
adb shell pm grant <package_name> android.permission.WRITE_EXTERNAL_STORAGE

You need to get this dialog to appear, so can you can grant access (if it doesnt appear from Build & Run, then close the app, start app from Library / unknown sources)

Resources:
https://developer.oculus.com/distribute/latest/concepts/publish-mobile-manifest/
https://forums.oculusvr.com/developer/discussion/78412/accessing-local-files


10 Comments + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch Instagram

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.