//获取安装的应用名称
private List<String> getInstalledAppNames(){
List<PackageInfo> packages =this.getPackageManager().getInstalledPackages(0);
List<String> appNames = new ArrayList<String>();
for(PackageInfo info : packages){
if((info.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM)==0){
String appName =getProgramNameByPackageName(info.packageName);
appNames.add(appName);
}
}
return appNames;
}
//根据包名获取应用名称
private String getProgramNameByPackageName(String packageName) {
PackageManager pm = this.getPackageManager();
String name = null;
try {
name = pm.getApplicationLabel(pm.getApplicationInfo(packageName,PackageManager.GET_META_DATA)).toString();
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return name;
}