3
private List<App> loadInstalledApps(boolean includeSysApps) {
PackageManager appInfo = getPackageManager();
List<ApplicationInfo> listInfo = appInfo.getInstalledApplications(PackageManager.GET_META_DATA);
Collections.sort(listInfo, new ApplicationInfo.DisplayNameComparator(appInfo));
List<App> data = new ArrayList<App>();
for (int index = 0; index < listInfo.size(); index++) {
try {
ApplicationInfo content = listInfo.get(index);
if ((content.flags != ApplicationInfo.FLAG_SYSTEM) && content.enabled) {
if (content.icon != 0) {
App item = new App();
if(!item.isFavourite())
{
item.setTitle(getPackageManager().getApplicationLabel(content).toString());
item.setPackageName(content.packageName);
item.setIcon(getPackageManager().getDrawable(content.packageName, content.icon, content));
long installed = appInfo.getPackageInfo(content.packageName, 0).firstInstallTime;
Date installedDate = new Date(installed);
// create a date time formatter
SimpleDateFormat formatter = new SimpleDateFormat(
"dd/MM/yyyy");
String firstInstallDate = formatter.format(installedDate);
item.setSize(firstInstallDate);
data.add(item);
}
else if(item.isFavourite())
{
item.setTitle(getPackageManager().getApplicationLabel(content).toString());
item.setPackageName(content.packageName);
item.setIcon(getPackageManager().getDrawable(content.packageName, content.icon, content));
data.add(item);
}
}
}
} catch (Exception e) {
}
}
return data;
}
現在發生了什麼? –