雷神索尔怎么死的:Get installed Applications with Name, Package Name, Version and Icon

来源:百度文库 编辑:九乡新闻网 时间:2024/04/24 21:40:04
Get installed Applications with Name, Package Name, Version and Icon
5 votes · 6 comments
This helper function retrieves all installed apps with the application name, package name, version-number and -code as well as the icons. The method getPackages() returns an ArrayList with all the apps.
·
copy
',1)">
·download
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
private ArrayList getPackages() {
ArrayList apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; iapps.get(i).prettyPrint();
}
return apps;
}
private ArrayList getInstalledApps(boolean getSysPackages) {
ArrayList res = new ArrayList();
List packs = getPackageManager().getInstalledPackages(0);
for(int i=0;iPackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}