- Home /
Detect if app is installed on Android
We are developing a Unity application which needs to check if certain apps are already installed or not on the device. We managed to do this easily on iOS using PlayerPrefs and Xcode, but we don't know how to do the same on Android.
There are lots of questions like this on the web but no one applies dircetly to Unity, so we are in need for some help or hints. Thanks!
@DanjelRicci , how did you manage to get it to work on IOS? can you please explain
Answer by alok_androider · Jun 20, 2014 at 05:31 PM
public bool IsAppInstalled(string bundleID){
#if UNITY_ANDROID
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
Debug.Log(" ********LaunchOtherApp ");
AndroidJavaObject launchIntent = null;
//if the app is installed, no errors. Else, doesn't get past next line
try{
launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage",bundleID);
//
// ca.Call("startActivity",launchIntent);
}catch(Exception ex){
Debug.Log("exception"+ex.Message);
}
if(launchIntent == null)
return false;
return true;
#else
return false;
#endif
say i want a button which will open the other app like Skype/viber or anything that can have bundle id on android ,else it will redirect it to redirect to google can we do that .
i mean will catch of (try-catch ) execute so that i can put application.openurl
You're absolutely right. You should use the Catch for opening the playstore by calling Application.OpenURL.
The solution works great if I had to test if app is installed, But in my case I need to know if app is not installed.
launchIntent = package$$anonymous$$anager.Call<AndroidJavaObject("getLaunchIntentForPackage",bundleID);
throws Java exception which is not caught by c# catch statement, which breaks further code execution. Can you suggest workaround? I would be thankful if any solution provided. False is never returned in this case
Hey, i have updated the answer, we need to handle Exception not UnityException. Cheers. @royperetz , What problem you are facing and do you need to check installed apps Android or Ios
Thank you, I ended up creating android plugin and handled exception in plugin, But if exception works then this is even great
Hi! I have the same problem, can you share your solution? What plugin should i use? Thnx
Your answer
![](https://koobas.hobune.stream/wayback/20220613131958im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make an android app a "trial" version 2 Answers
Signing an Android application 1 Answer
Why does .apk file being built consumes so much space? 1 Answer
Detect if app is installed on iOS 0 Answers
ultility app 0 Answers