is Package Exists - Android android.content.pm

Android examples for android.content.pm:PackageManager

Description

is Package Exists

Demo Code

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

public class Main {

  public static boolean isPackageExists(Context context, String packageName) {
    if (null == packageName || "".equals(packageName)) {
      throw new IllegalArgumentException("Package name cannot be null or empty !");
    }//from www .  ja v a2s  .  c  o m
    try {
      ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName,
          PackageManager.GET_UNINSTALLED_PACKAGES);
      return null != info;
    } catch (NameNotFoundException e) {
      return false;
    }
  }

}

Related Tutorials