Tuesday, February 14, 2012

How to Detect if an app is installed in device?

If you ever need to know if a particular app is installed on the user's device, you can use the PackageManager.  From a Context class (e.g. an Activity or a Service) you can call getPackageManager().  This gives you a variety of methods, one of which is getPackageInfo().  Below is a method you might use.  You might call it like this:

isAppInstalled("com.simexusa.campusmaps_full");

private boolean isAppInstalled(String uri) {
PackageManager pm = getPackageManager();
boolean installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}

No comments:

Post a Comment