I’ve been faffing around for ages with this trying to get a solution, and keep getting to the same sticking point. I’m using Unity 6 LTS, on an apple silicone Mac and developing for Quest 3.
I need to grant permissions (done) and choose a file or folder from local storage (eventually a USB plugged into the headset but am testing with local DCIM etc as well).
After jumping through many iterations my latest attempt is using Native File Picker for Android & iOS | Integration | Unity Asset Store
It pops up fine. I can choose a file fine. But then - stop. Black screen. The application is paused. If I hit the oculus button it unpauses - but nothing I can do can force it to do this without pressing the oculus button.
This is my “triggering” code:
Debug.Log("Just trying to load video from USB!");
string[] fileTypes = new string[] { "image/*", "video/*" };
NativeFilePicker.Permission permission = NativeFilePicker.PickMultipleFiles( ( paths ) =>
{
if( paths == null )
Debug.Log( "Operation cancelled" );
else
{
for( int i = 0; i < paths.Length; i++ )
Debug.Log( "Picked file: " + paths[i] );
}
// Force XR restart immediately after the file picker
Debug.Log("Restarting XR after file picker...");
StartCoroutine(RestartXR());
}, fileTypes );
Debug.Log( "Permission result: " + permission );
The co-routine (which I added afterwards) after reading around lots is this:
IEnumerator RestartXR()
{
Debug.Log("Stopping XR...");
XRGeneralSettings.Instance.Manager.StopSubsystems();
Debug.Log("XR stopped.");
// Allow the system to settle
yield return new WaitForEndOfFrame();
Debug.Log("Starting XR...");
XRGeneralSettings.Instance.Manager.StartSubsystems();
Debug.Log("XR restarted.");
// Reactivate the camera
EnsureCameraIsActive();
}
but nothing in the callback is called until after I unpause with the oculus button.
I’ve also tried forcing it (though I don’t want this as a solution as I want to be able to pause deliberately!)
void OnApplicationPause(bool pause)
{
Debug.Log($"Application pause state changed. Paused: {pause}");
if (pause)
{
Debug.Log("Unity is paused, forcing activity to resume...");
BringUnityToForeground(); // Forces Unity back to the foreground
}
}
and
void BringUnityToForeground()
{
using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
currentActivity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
{
Debug.Log("Forcing Unity activity to resume...");
currentActivity.Call("onResume");
// Explicitly restart XR after onResume
Debug.Log("Restarting XR after forcing activity to resume...");
StartCoroutine(RestartXR());
}));
}
}
but that doesn’t seem to actually unpause either!
I’m tearing what’s left of my hair out. I’m still learning (lots) but when things just “don’t work” like this it can be so confusing!