0

How can I check whether an app is installed with getPackageManager? I have no idea. Thanks. Android.

    Intent intent = new Intent();
    intent.setClassName("PACKAGE_NAME", "PACKAGE_NAME.TARGET_ACTIVITY");
    if (isCallable(context, intent)) {
        // Attach any extras, start or start with callback
    } else {
        // Respond to the application or activity not being available
    }

4 Answers4

0
protected boolean isAppInstalled(String packageName) {
        Intent mIntent = getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME);
        if (mIntent != null) {
            return true;
        }
        else {
            return false;
        }
    }
Andromeda
  • 1,370
  • 2
  • 10
  • 15
0

You can get list of installed apps by using the below code snippet

PackageManager packageManager = getPackageManager();
  List<ApplicationInfo> list = packageManager.getInstalledApplications(PackageManager.GET_META_DATA)

Now you can get package name for each installed app, and then can perform a check for package name

ApplicationInfo data = appsList.get(position);
String packageName = data.packageName;

Checkout another example How to Get List of Installed Apps in Android

Nilanchala
  • 5,891
  • 8
  • 42
  • 72
0

I think queryIntentActivities is more appropriet since you have a target activity defined in your intent. If the list return is of .size() == 0. Then it's safe to say it's not available.

protected boolean isCallable(Context context, Intent intent) {
    List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent, 0);
    return activities.size() > 0 ? true : false;
}
JRomero
  • 4,878
  • 1
  • 27
  • 49
0

Try this :

private boolean appInstalledorNot(String packageName) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
    pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
    app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
    app_installed = false;
}
return app_installed;
}
AK Ali
  • 152
  • 1
  • 6