我正在开发一个应用程序,其中我从系统中获取已安装的应用程序。并成功显示在列表视图中。我成功地得到了每一件事。但现在它也让我得到了我不想要的系统应用程序。像这样的系统应用程序...浏览器,设置,闹钟这样我就不需要了。那么我该怎么做才能过滤呢?你能帮我解决这个...
代码 ::
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
// Fill PackageInfo
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;
PackageManager pm = getPackageManager();
ApplicationInfo appInfo;
try {
// Get all app information in Application info
appInfo = pm.getApplicationInfo(newInfo.pname, 0);
String appFile = appInfo.sourceDir;
newInfo.size = String.valueOf(new File(appFile).length());
long installed = new File(appFile).lastModified();
newInfo.date = String.valueOf(installed);
Date dtappdate = new Date(installed);
newInfo.instdate = String.valueOf(dtappdate.toString());
} catch (NameNotFoundException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}