I’m trying to use a file picker on Magic Leap 2 with Unity and MRTK3 that allows users to browse and select a file using the system’s file browser. The picker should return the full file path (including the filename and extension) so I can access the selected file within my Unity application.
Unity version: Unity 6 (6000.0.37f1)
ML2 OS version: 1.12.0
Host OS: Windows 11
MRTK version: MRTK3
Here’s the method I’m currently trying to use for Magic Leap 2:
private async Task<string> FilePicker_Android()
{
using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
using (AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
using (AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent", "android.intent.action.OPEN_DOCUMENT"))
{
intent.Call<AndroidJavaObject>("setType", "*/*");
intent.Call<AndroidJavaObject>("addCategory", "android.intent.category.OPENABLE");
currentActivity.Call("startActivityForResult", intent, 42);
}
// I want to return the selected file path here
string filePath = ""; // How can I get the file path from the Intent's result?
return filePath;
}
Trough that code i can successfully open the file browser on the device. But once i select a file, nothing happens—the result isn’t returned to Unity. I have no idea how to get the filepath from the intent. I have the required storage rights because I can query and load files with an direct path → e.g. “/storage/emulated/0/Datasets/data.csv”
Has anyone successfully implemented a working file picker on Magic Leap 2? What’s the best approach to retrieve the selected file path in Unity? Any help would be greatly appreciated!