-13

I have seen some apps where you get an in-app reward for installing another app. These are usually able to check whether or not the app is present on the device, and I'm wondering how they're able to do this.

How can I, from an Android app, check if a specific app is installed on the device?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Zoe
  • 27,060
  • 21
  • 118
  • 148

1 Answers1

2

Define a method that returns true if the PackageManager can find it:

Example:

private boolean checkThisApp(String uri) {
    PackageManager myPackageManager = getPackageManager();
    boolean app_installed;
    try {
        myPackageManager.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        app_installed = true;
    }
    catch (PackageManager.NameNotFoundException e) {
        app_installed = false;
    }
    return app_installed;
}
    
    

and use it in the Activity/Fragment like:

boolean isAppInstalled = checkThisApp("com.facebook.katana"); 
Community
  • 1
  • 1
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • 1
    It should, it uses Android's package manager to query all installed packages. You could also take a look at http://stackoverflow.com/questions/2695746/how-to-get-a-list-of-installed-android-applications-and-pick-one-to-run – LuigiPower Jul 23 '16 at 08:41