unity3d 获取所有安装应用包名和应用名 android C#版

废话不多直接上代码

 public static List GetAllApk()
    {
        List apks = new List ();
#if UNITY_ANDROID
        try
        {
            AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = up.GetStatic("currentActivity");
            AndroidJavaObject packageManager = currentActivity.Call("getPackageManager");
            AndroidJavaObject packageInfos = packageManager.Call("getInstalledPackages", 0);
            AndroidJavaObject[] packages = packageInfos.Call("toArray");
            for (int i = 0; i < packages.Length;i++ )
            {
                AndroidJavaObject applicationInfo = packages[i].Get("applicationInfo");
                if ((applicationInfo.Get("flags") & applicationInfo.GetStatic("FLAG_SYSTEM")) == 0)// 判断是不是系统应用
                {
                    string packageName = applicationInfo.Get("packageName");
                    AndroidJavaObject applicationLabel = packageManager.Call("getApplicationLabel", applicationInfo);
                    string packageLable = applicationLabel.Call("toString");
                    apks.Add(packageLable + "|" + packageName);
                }
            }
        }
        catch (System.Exception e)
        {
        }
#endif
        return apks;
    }

你可能感兴趣的:(unity3d 获取所有安装应用包名和应用名 android C#版)