Android How to - Check if App has installed








Question

We would like to know how to check if App has installed.

Answer

The following code shows how to check if an App has installed by using the package name.

It catches the package not found exception and returns false if the app is not installed.

//from w  ww  . j  av  a2  s .c  o  m

import android.content.Context;
import android.content.pm.PackageManager;

public class Main {
  public static boolean appInstalledOrNot(Context context, String packageName) {
    try {
      context.getPackageManager().getPackageInfo(packageName,
          PackageManager.GET_ACTIVITIES);
      return true;
    } catch (PackageManager.NameNotFoundException e) {
      return false;
    }
  }

}