Saturday, 26 November 2011

Android - Detect if an application has been installed

All the applications in Android has a package name, which should be unique for each application. For example, all my applications start with the package name:
com.jiahaoliuliu.android

This property could be used to check if a specific application has been installed by asking the package manager.

Here is the sample code for a program:

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;
}


And here is a list of package name:
  • Facebook: com.facebook.katana
  • Twitter: com.twitter.android
  • Gmail: com.google.android.gm
  • Skype: com.skype.raider
  • YouTube: com.google.android.youtube

No comments:

Post a Comment