0 votes
by (1.5k points)
recategorized by

Please help - I need to launch a default pico File Manager from Unity Application - how to invoke it with native android intent?

1 Answer

0 votes
by (1.9k points)
edited by
 
Best answer

c# script method

 private static void openFM()
        {
#if UNITY_ANDROID
AndroidJavaClass androidInstance = new AndroidJavaClass("com.your.android.LibraryClass");
 if(androidInstance!=null) androidInstance.CallStatic("openFileManager");
 androidInstance.Dispose();
#endif
        }

android library class:

package com.your.android;
public class LibraryClass {
    public static void openFileManager() {
            Activity unityActivity = UnityPlayer.currentActivity;
            Intent intent = unityActivity.getPackageManager().getLaunchIntentForPackage("com.pvr.filemanager");
            if (intent != null) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                unityActivity.startActivity(intent);
            }  
    }

}

its worked on pico neo2 but if filemanager be openned before by pico default launcher then filemanger must be closed before in shortcut menu (double click pico button on controller)

maybe it can do only by c# script but I dont test this code

AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        string picoFileManagerPackageName = "com.pvr.filemanager";
        AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
        AndroidJavaObject packageManager = currentActivity.Call<AndroidJavaObject>("getPackageManager");
        AndroidJavaObject launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", picoFileManagerPackageName);
        currentActivity.Call("startActivity", launchIntent);
...