public static PackageParser.Package getPackageInfoFromPackage( String filePath, boolean collectSignature) { PackageParser packageParser = new PackageParser(filePath); File sourceFile = new File(filePath); DisplayMetrics metrics = new DisplayMetrics(); metrics.setToDefaults(); PackageParser.Package pkg = packageParser.parsePackage(sourceFile, filePath, metrics, 0); if (pkg != null && collectSignature) { packageParser.collectCertificates(pkg, 0); } return pkg; }
public static Drawable getIconFromPackage(Context context, String archiveFilePath) { PackageParser packageParser = new PackageParser(archiveFilePath); File sourceFile = new File(archiveFilePath); DisplayMetrics metrics = new DisplayMetrics(); metrics.setToDefaults(); PackageParser.Package pkg = packageParser.parsePackage(sourceFile, archiveFilePath, metrics, 0); if (pkg == null) { return context.getResources().getDrawable(R.drawable.android); } ApplicationInfo info = pkg.applicationInfo; Resources pRes = context.getResources(); AssetManager assmgr = new AssetManager(); assmgr.addAssetPath(archiveFilePath); Resources res = new Resources(assmgr, pRes.getDisplayMetrics(), pRes.getConfiguration()); if (info.icon != 0) { Drawable icon = res.getDrawable(info.icon); return icon; } else { return context.getResources().getDrawable(R.drawable.android); } }