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