Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; public class Main { public static PackageInfo getLocalPackageInfo(Context context) { return getLocalPackageInfo(context, 0); } public static PackageInfo getLocalPackageInfo(Context context, int flag) { PackageManager pm = context.getPackageManager(); PackageInfo pkgInfo = null; try { pkgInfo = pm.getPackageInfo(context.getPackageName(), flag); } catch (Exception e) { e.printStackTrace(); } return pkgInfo; } public static PackageInfo getPackageInfo(Context context, String apkFilepath) { return getPackageInfo(context, apkFilepath, PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES); } public static PackageInfo getPackageInfo(Context context, String apkFilepath, int flag) { PackageManager pm = context.getPackageManager(); PackageInfo pkgInfo = null; try { pkgInfo = pm.getPackageArchiveInfo(apkFilepath, flag); } catch (Exception e) { e.printStackTrace(); } return pkgInfo; } }