How can I find if a particular package exists on my Android device?

brig picture brig · Jul 20, 2011 · Viewed 47.1k times · Source

How can I find whether a particular package or application, say: com.android.abc, exists on my Android device?

Answer

Rasel picture Rasel · Jul 20, 2011

Call any of the below method with the package name.

import android.content.pm.PackageManager;

// ...

    public boolean isPackageExisted(String targetPackage){
        List<ApplicationInfo> packages;
        PackageManager pm;

        pm = getPackageManager();        
        packages = pm.getInstalledApplications(0);
        for (ApplicationInfo packageInfo : packages) {
            if(packageInfo.packageName.equals(targetPackage))
                return true;
        }
        return false;
    }

 import android.content.pm.PackageManager;

 public boolean isPackageExisted(String targetPackage){
   PackageManager pm=getPackageManager();
   try {
     PackageInfo info=pm.getPackageInfo(targetPackage,PackageManager.GET_META_DATA);
   } catch (PackageManager.NameNotFoundException e) {
     return false;
   }  
   return true;
 }