is New Apk Installed by package name and version - Android App

Android examples for App:APK Install and Uninstall

Description

is New Apk Installed by package name and version

Demo Code


//package com.java2s;
import java.util.List;
import android.content.Context;

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

public class Main {

    public static boolean isNewApkInstalled(Context context,
            String packageName, int version) {
        PackageManager pkgManager = context.getPackageManager();

        List<PackageInfo> pkgs = pkgManager
                .getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
        for (PackageInfo pkg : pkgs) {
            if (packageName.equals(pkg.packageName)
                    && pkg.versionCode == version) {
                return true;
            }//from w w w.  j  a v  a  2  s .c o  m
        }
        return false;
    }

    public static List<PackageInfo> getInstalledPackages(Context context) {
        PackageManager pkgManager = context.getPackageManager();
        return pkgManager
                .getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
    }
}

Related Tutorials