Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 966
brig Avatar asked Jul 20 '11 08:07

brig


People also ask

Does Android have a package manager?

Package Manager is a highly powerful application to manage apps, both system and user, installed on an android device.

How do you find a package name?

One method to look up an app's package name is to find the app in the Google Play app store using a web browser. The package name will be listed at the end of the URL after the '? id='. In the example below, the package name is 'com.google.android.gm'.

What is the package name in Android?

All Android apps have a package name. The package name uniquely identifies the app on the device; it is also unique in the Google Play store.


2 Answers

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;
 }
like image 115
Rasel Avatar answered Oct 19 '22 11:10

Rasel


Without using a try-catch block or iterating through a bunch of packages:

public static boolean isPackageInstalled(Context context, String packageName) {
    final PackageManager packageManager = context.getPackageManager();
    Intent intent = packageManager.getLaunchIntentForPackage(packageName);
    if (intent == null) {
        return false;
    }
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}
like image 30
Kavi Avatar answered Oct 19 '22 11:10

Kavi