我的问题是如何获取安装在Android上的所有应用程序的标签。 我在努力
pm = (PackageManager)getApplicationContext().getPackageManager();
List<ApplicationInfo> list = pm.getInstalledApplications(0);
for (ApplicationInfo appInfo : list) {
try {
deviceApps.add((String) appInfo.loadLabel(pm));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
但它不起作用。请帮助我。 问候
答案 0 :(得分:9)
以下是完整的代码:
ArrayList<PackageInfo> res = new ArrayList<PackageInfo>();
PackageManager pm = ctx.getPackageManager();
List<PackageInfo> packs = pm.getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
String description = (String) p.applicationInfo.loadDescription(pm);
String label= p.applicationInfo.loadLabel(pm).toString();
String packageName = p.packageName;
String versionName = p.versionName;
String versionCode = p.versionCode;
String icon = p.applicationInfo.loadIcon(pm);
//Continue to extract other info about the app...
}
注意:将此权限添加到清单文件中:
<uses-permission android:name="android.permission.GET_TASKS" />