获取已安装的程序和APK文件的信息

 

对于APK文件
PackageManager mPackageManager = getPackageManager();
PackageInfo p = mPackageManager.getPackageArchiveInfo(<file path>, 0);

if (p != null) {
 ApplicationInfo appInfo = p.applicationInfo;
 String appname = mPackageManager.getApplicationLabel(appInfo)
   .toString();
 String packageName = p.packageName;
 String versionName = p.versionName;
 Drawable icon = mPackageManager.getApplicationIcon(appInfo);
}

 

对于已安装的程序

// get all installed application
PackageManager mPackageManager = getPackageManager();
List<PackageInfo> packs = mPackageManager.getInstalledPackages(0);

for (int i = 0; i < packs.size(); i++) {
 PackageInfo p = packs.get(i);

 if (p.applicationInfo.sourceDir.startsWith("/system/app")) {
  // ignore system application
  continue;
 }

 // get application detail
 ApplicationInfo appInfo = p.applicationInfo;
 String appname = mPackageManager.getApplicationLabel(appInfo)
   .toString();
 String packageName = p.packageName;
 String versionName = p.versionName;
 Drawable icon = mPackageManager.getApplicationIcon(appInfo);
}

你可能感兴趣的:(String,File,null,application,System,Path)