Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import java.io.File; import java.util.List; public class Main { /** * To check whether the apk file has installed. * * @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; } /** * Get the package info of the specified apk file. * * @param context the context * @param apkFile the apk file * @return */ public static PackageInfo getApkInfo(Context context, File apkFile) { if (context == null || apkFile == null || !apkFile.exists()) { return null; } PackageManager packageManager = context.getPackageManager(); PackageInfo pkgInfo = packageManager.getPackageArchiveInfo(apkFile.getAbsolutePath(), PackageManager.GET_ACTIVITIES); return pkgInfo; } }