我有以下代码,它可以很好地获取安装在android中的所有应用程序的详细信息,但是当我使用isSystemPackage(ResolveInfo)使用过滤器时,它会强制关闭。
try {
lView = (ListView) findViewById(R.id.list1);
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
{
List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
if (isSystemPackage(rInfo)) {
results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
Log.w("Installed Applications", rInfo.activityInfo.applicationInfo
.loadLabel(pm).toString());
}
}
}
} catch(Exception ex) {
Toast.makeText(getApplicationContext(), ex.toString(), 4000).show();
}
它会生成强制关闭
isSystemPackage()代码是
private boolean isSystemPackage(ResolveInfo ri){
return ((ri.activityInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM)!=0)?
true:false;
}
我试图调试它但无法做到。
答案 0 :(得分:8)
得到我的答案,这是其他人使用此代码。
List<ApplicationInfo> list = getPackageManager().getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
for (int n=0;n<list.size();n++) {
if((list.get(n).flags & ApplicationInfo.FLAG_SYSTEM)!=1)
{
results.add(list.get(n).loadLabel(pm).toString());
Log.w("Installed Applications", list.get(n).loadLabel(pm).toString());
}
}
欢呼:)
答案 1 :(得分:2)
请尝试这种方法。它对我有用:
List<ApplicationInfo> applications = getPackageManager().getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
for (int n=0; n < applications.size(); n++)
{
if ((applications.get(n).flags & ApplicationInfo.FLAG_SYSTEM) != 1)
{
Log.i(tag , "Non-System Aplication name " + applications.get(n).name);
}
}