get Installed Apk Package Info - Android android.content.pm

Android examples for android.content.pm:Apk Install

Description

get Installed Apk Package Info

Demo Code

import java.util.Iterator;
import java.util.List;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class Main {

  public static PackageInfo getInstalledApkPackageInfo(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    List<PackageInfo> apps = pm.getInstalledPackages(PackageManager.GET_SIGNATURES);

    Iterator<PackageInfo> it = apps.iterator();
    while (it.hasNext()) {
      PackageInfo packageinfo = it.next();
      String thisName = packageinfo.packageName;
      if (thisName.equals(packageName)) {
        return packageinfo;
      }/*from   w  ww  .j a  v a  2 s  .c o m*/
    }

    return null;
  }

}

Related Tutorials