Example usage for android.content.pm PackageManager getInstalledPackages

List of usage examples for android.content.pm PackageManager getInstalledPackages

Introduction

In this page you can find the example usage for android.content.pm PackageManager getInstalledPackages.

Prototype

public abstract List<PackageInfo> getInstalledPackages(@PackageInfoFlags int flags);

Source Link

Document

Return a List of all packages that are installed for the current user.

Usage

From source file:Main.java

/**
 * @param context/*from   w w w .  ja v  a 2s.c  o m*/
 * @param packageName
 * @return
 */
public static boolean isAvilible(Context context, String packageName) {
    final PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
    packageManager.getInstalledApplications(packageManager.GET_META_DATA);
    List<String> packageNames = new ArrayList<String>();
    if (packageInfos != null) {
        for (int i = 0; i < packageInfos.size(); i++) {
            String packName = packageInfos.get(i).packageName;
            packageNames.add(packName);
        }
    }
    return packageNames.contains(packageName);
}

From source file:Main.java

public static boolean cheakByPackageName(Context context, String packageName, String sdkVersion) {
    final PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    List<String> pName = new ArrayList<String>();
    List<String> versions = new ArrayList<String>();

    if (pinfo != null) {
        for (int i = 0; i < pinfo.size(); i++) {
            String pn = pinfo.get(i).packageName;
            String appVersion = pinfo.get(i).versionName;
            pName.add(pn);/*from w w w  .j  a v a2s.c  o m*/
            versions.add(appVersion);
        }
    }

    if (!pName.contains(packageName)) {
        return false;
    } else {
        if (!versions.contains(sdkVersion)) {
            return false;
        }

    }
    return true;
}

From source file:Main.java

/**
 * @param context/*from   w  w w.j  a v  a 2s  .co  m*/
 * @return List<PackageInfo>
 * @throws
 * @Title: getPackageInfo
 * @Description: TODO
 */
public static List<PackageInfo> getPackageInfo(Context context) {

    List<PackageInfo> appList = new ArrayList<PackageInfo>();

    PackageManager mPackageManager = context.getPackageManager();

    List<PackageInfo> packageList = mPackageManager.getInstalledPackages(0);
    for (int i = 0; i < packageList.size(); i++) {
        PackageInfo pi = (PackageInfo) packageList.get(i);
        appList.add(pi);
    }
    return appList;
}

From source file:Main.java

/**
 * To check whether the apk file has installed.
 * /*from  w  w  w.java  2s.  co  m*/
 * @param  context the context
 * @param  apkFile the apk file
 * @return         true if installed, otherwise return false
 */
public static boolean isApkInstalled(Context context, File apkFile) {
    if (context == null || apkFile == null || !apkFile.exists()) {
        return false;
    }

    PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> installedPkgs = packageManager.getInstalledPackages(0);
    PackageInfo pkgInfo = getApkInfo(context, apkFile);
    if (pkgInfo != null) {
        String pkgName = pkgInfo.packageName;

        for (PackageInfo info : installedPkgs) {
            if (pkgName.equals(info.packageName)) {
                return true;
            }
        }
    }

    return false;
}

From source file:Main.java

public static boolean haveGooglePlay(Context context, String packageName) {
    //Get PackageManager
    final PackageManager packageManager = context.getPackageManager();
    //Get The All Install App Package Name
    List<PackageInfo> pInfo = packageManager.getInstalledPackages(0);

    //Create Name List
    List<String> pName = new ArrayList<String>();

    //Add Package Name into Name List
    if (pInfo != null) {
        for (int i = 0; i < pInfo.size(); i++) {
            String pn = pInfo.get(i).packageName;
            pName.add(pn);//from   w w  w  .j a  v  a 2 s  . c o  m
        }
    }

    //Check
    return pName.contains(packageName);
}

From source file:Main.java

static void askEveryone(final Context context, boolean optedOut, boolean shouldUpdate) {
    Boolean status = false;//from  w w  w.j a v a2s.  com
    PackageManager pm = context.getPackageManager();
    if (pm != null) {
        for (PackageInfo info : pm.getInstalledPackages(0)) {
            if (!info.packageName.equals(context.getPackageName())) {
                try {
                    Context foreignContext = context.createPackageContext(info.packageName, 0);
                    if (shouldUpdate) {
                        if (isQuantified(foreignContext)) {
                            createOptOut(foreignContext, optedOut);
                        }
                    } else {
                        status = isOptedOut(foreignContext, false);
                        if (status) {
                            break;
                        }
                    }
                } catch (Exception ignored) {
                }
            }
        }
    }
    if (!shouldUpdate) {
        createOptOut(context, status);
    }
}

From source file:de.schildbach.wallet.util.CrashReporter.java

public static void appendInstalledPackages(final Appendable report, final Context context) throws IOException {
    final PackageManager pm = context.getPackageManager();
    final List<PackageInfo> installedPackages = pm.getInstalledPackages(0);

    // sort by package name
    Collections.sort(installedPackages, new Comparator<PackageInfo>() {
        @Override/*from w w w.  ja  va 2 s . c  o m*/
        public int compare(final PackageInfo lhs, final PackageInfo rhs) {
            return lhs.packageName.compareTo(rhs.packageName);
        }
    });

    for (final PackageInfo p : installedPackages)
        report.append(String.format(Locale.US, "%s %s (%d) - %tF %tF\n", p.packageName, p.versionName,
                p.versionCode, p.firstInstallTime, p.lastUpdateTime));
}

From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java

/**
 * ?? ???????/*w  w  w  .ja v a  2 s . c o m*/
 * 
 * @return
 */
public static List<PackageInfo> getInstalledUserApps(Context context) {
    PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> result = new ArrayList<PackageInfo>();
    List<PackageInfo> list = packageManager.getInstalledPackages(0);// ?
    for (PackageInfo packageInfo : list) {
        if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <= 0) { // ???
            result.add(packageInfo);
        }
    }
    return result;
}

From source file:com.example.common.MarketAPI.java

/**
 *  /*w ww.jav  a  2 s  . c o  m*/
 */
public static void submitAllInstalledApps(final Context context) {

    PackageManager pm = context.getPackageManager();
    List<PackageInfo> packages = pm.getInstalledPackages(0);
    ArrayList<UpgradeInfo> appList = new ArrayList<UpgradeInfo>();
    for (PackageInfo info : packages) {
        UpgradeInfo app = new UpgradeInfo();
        app.name = String.valueOf(info.applicationInfo.loadLabel(pm));
        app.versionName = info.versionName;
        app.versionCode = info.versionCode;
        app.pkgName = info.packageName;
        appList.add(app);
    }
    final HashMap<String, Object> params = new HashMap<String, Object>(1);
    params.put("appList", appList);
    new ApiAsyncTask(context, MarketAPI.ACTION_SYNC_APPS, null, params).execute();
}

From source file:com.gm.goldencity.util.Utils.java

/**
 * Getting all installed packages/*from w  ww .  java2 s .c o m*/
 *
 * @param context Application context
 * @return all installed applications list
 */
public static List<PackageInfo> getAllInstalledApplication(Context context) {
    final PackageManager pm = context.getPackageManager();
    // get a list of installed apps.
    List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.GET_META_DATA);

    return packages;
}