I am trying to run an android from Unity3D in C #, everything is in place, except for the detection of installed applications.
I tried a lot of different things, but they all get stuck in one place, referring to getInstalledApplicationsthe PackageManager .
I think I managed to replicate the class ApplicationInfoin C #, at least with variable memory, by studying the android source, so I don't think the problem is at least not yet ...
Simply put, I need a URI (or something that I can use to open the application), the name of the application and the application icon (either a string for its location, or itself Texture2D), I'm trying to use ApplicationInfobecause it has it all, and then some, but if I need to get them individually or using another method, this is completely normal.
Here is an example of what I'm doing now. This happens whether I use a class or an object.
void Start () {
AndroidJavaClass pluginClass = new AndroidJavaClass("android.content.pm.PackageManager");
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = jc.GetStatic<AndroidJavaObject>("currentActivity");
Debug.Log(currentActivity.Call<string>("getPackageName"));
int flag = pluginClass.GetStatic<int>("GET_META_DATA");
AndroidJavaClass syspackage = currentActivity.Call<AndroidJavaClass>("getPackageManager");
And here is the error I get
AndroidJavaException: Java.lang.NoSuchMethodError: no method with name = 'getInstalledApplications' signature=Ljava/lang/Class;' in class Lcom.unity3d/player/UnityPlayerActivity;
How do I do this job? Or can you tell / show me another method that will achieve the goal?
// EDIT
Okay, I messed it up for HOURS, trying every possible combination, and I got it.
AndroidJavaClass pluginClass = new AndroidJavaClass("android.content.pm.PackageManager");
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = jc.GetStatic<AndroidJavaObject>("currentActivity");
int flag = pluginClass.GetStatic<int>("GET_META_DATA");
AndroidJavaObject pm = currentActivity.Call<AndroidJavaObject>("getPackageManager");
AndroidJavaObject syspackages = pm.Call<AndroidJavaObject>("getInstalledApplications", flag);
, ints, Java, # ints, , ....