androidandroid-applicationinfo

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


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


Solution

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