unity3d android 获取是否安装app
废话不多直接上代码
public static bool IsInstallApp(string packageAndroidName)
{
#if (UNITY_ANDROID && !UNITY_EDITOR) || ANDROID_CODE_VIEW
try
{
using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using (AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
{
using (AndroidJavaObject packageManager = currentActivity.Call<AndroidJavaObject>("getPackageManager"))
{
try
{
using (AndroidJavaObject launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", packageAndroidName))
{
if (launchIntent == null)
{
return false;
}
else
{
return true;
}
}
}
catch (System.Exception)
{
}
}
}
}
}
catch (System.Exception e)
{
}
return false;
#endif
return false;
}
注意:获取一次之后可以存储下来,防止重复访问