if(){}
/**
- 获取apk包的信息:版本号,名称,图标等
- @param absPath apk包的绝对路径
- @param context
/
public void apkInfo(String absPath,Context context) {
PackageManager pm = context.getPackageManager();
PackageInfo pkgInfo = pm.getPackageArchiveInfo(absPath,PackageManager.GET_ACTIVITIES);
if (pkgInfo != null) {
ApplicationInfo appInfo = pkgInfo.applicationInfo;
/ 必须加这两句,不然下面icon获取是default icon而不是应用包的icon /
appInfo.sourceDir = absPath;
appInfo.publicSourceDir = absPath;
String appName = pm.getApplicationLabel(appInfo).toString();// 得到应用名
String packageName = appInfo.packageName; // 得到包名
String version = pkgInfo.versionName; // 得到版本信息
/ icon1和icon2其实是一样的 */
Drawable icon1 = pm.getApplicationIcon(appInfo);// 得到图标信息
Drawable icon2 = appInfo.loadIcon(pm);
String pkgInfoStr = String.format("PackageName:%s, Vesion: %s, AppName: %s", packageName, version, appName);
Log.i(TAG, String.format("PkgInfo: %s", pkgInfoStr));
}
}