How to get installed apps list with Unity3D?

Jonathan C

I'm trying to make an android launcher with Unity3D in C#, Everything is in place except detection of installed apps.

I have tried a lot of different things, but they all get stuck at the same place, accessing getInstalledApplications in the PackageManager.

I think I have managed to replicate the ApplicationInfo class in C#, at least variable storage wise, by studying the android source, so I don't think that's a problem, at least not yet...

Simply put, I need the URI (or something I can use to open the app), the name of the app, and the icon of the app (either a string to its location, or the Texture2D itself), I try for ApplicationInfo because it has all that and then some, but if I have to get them individually or through another method, that's totally fine.

Here is an example of what I am doing now. This happens regardless of 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's 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 make this work? Or can you tell/show me another method that will accomplish the goal?

//EDIT Okay I messed with this 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);

Now I just gotta figure out how to get the strings and ints i need out of the Java object and into C# strings and ints which is a totally different problem than this....

Radu Diță

You are passing a string as the param for getInstalledApplications instead of an integer.

You need to get your hands on an instance of PackageManager, to do this you'll need to get an Activity, fortunately, Unity can give you that.

AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = jc.GetStatic<AndroidJavaObject>("currentActivity");

AndroidJavaObject packageManager = currentActivity.Call<AndroidJavaObject>("getPackageManager");

int flag = pluginClass.GetStatic<int>("GET_META_DATA");

AndroidJavaObject[] arrayOfAppInfo = packageManager.Call<AndroidJavaObject[]>("getInstalledApplications", flag);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get list of installed Windows Universal Apps?

From Dev

How to get a comprehensive list of apps installed on wear device?

From Dev

How to get all share apps (installed on the device) in a list?

From Dev

How to get all share apps (installed on the device) in a list?

From Dev

Unable to get list of installed apps in a List<String>

From Dev

How to return list of installed Apps in alphabetical order

From Dev

How to get all share apps installed on the device?

From Dev

How to get installed applications in Android and no system apps?

From Dev

How to get model description list using c# in unity3d?

From Dev

Alphabetize List of Installed Apps

From Dev

Using Search API, can I get the list of installed apps on iOS?

From Dev

How to list all installed apps with manage.py in Django?

From Dev

How to randomly pick value from a list in Unity3D?

From Dev

Version check in ionic - how to get existing installed apps to update?

From Dev

How do I get GUID of apps installed from Microsoft Store?

From Dev

django 1.10 list of installed apps

From Dev

How to get value Unity3D InputField GUI

From Dev

How to get the average color of a sprite? (Unity3d)

From Dev

How do I get touch working in Unity3D?

From Dev

In unity3D, how to get the variable from other gameobject?

From Dev

Laravel + Unity3D = how to get the connected user?

From Dev

How to get value Unity3D InputField GUI

From Dev

How to GET and parse data from website? Unity3D

From Dev

How to get the list of installed library packages only?

From Dev

How to get list of installed applications on Windows 10?

From Dev

How to get the list of installed library packages only?

From Dev

How to get the list of installed packages without dependencies?

From Dev

How to get a list of applications installed in Ubuntu dash?

From Dev

How to include prerequisite apps in INSTALLED_APPS

Related Related

  1. 1

    How to get list of installed Windows Universal Apps?

  2. 2

    How to get a comprehensive list of apps installed on wear device?

  3. 3

    How to get all share apps (installed on the device) in a list?

  4. 4

    How to get all share apps (installed on the device) in a list?

  5. 5

    Unable to get list of installed apps in a List<String>

  6. 6

    How to return list of installed Apps in alphabetical order

  7. 7

    How to get all share apps installed on the device?

  8. 8

    How to get installed applications in Android and no system apps?

  9. 9

    How to get model description list using c# in unity3d?

  10. 10

    Alphabetize List of Installed Apps

  11. 11

    Using Search API, can I get the list of installed apps on iOS?

  12. 12

    How to list all installed apps with manage.py in Django?

  13. 13

    How to randomly pick value from a list in Unity3D?

  14. 14

    Version check in ionic - how to get existing installed apps to update?

  15. 15

    How do I get GUID of apps installed from Microsoft Store?

  16. 16

    django 1.10 list of installed apps

  17. 17

    How to get value Unity3D InputField GUI

  18. 18

    How to get the average color of a sprite? (Unity3d)

  19. 19

    How do I get touch working in Unity3D?

  20. 20

    In unity3D, how to get the variable from other gameobject?

  21. 21

    Laravel + Unity3D = how to get the connected user?

  22. 22

    How to get value Unity3D InputField GUI

  23. 23

    How to GET and parse data from website? Unity3D

  24. 24

    How to get the list of installed library packages only?

  25. 25

    How to get list of installed applications on Windows 10?

  26. 26

    How to get the list of installed library packages only?

  27. 27

    How to get the list of installed packages without dependencies?

  28. 28

    How to get a list of applications installed in Ubuntu dash?

  29. 29

    How to include prerequisite apps in INSTALLED_APPS

HotTag

Archive