开发者

How to filter nonsystem application from all installed applications

I have the following code and it works well to fetch the details of all applications installed in android but when i use a filter using isSystemPackage(ResolveInfo) it gives force close.

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).to开发者_开发知识库String());
                Log.w("Installed Applications", rInfo.activityInfo.applicationInfo
                        .loadLabel(pm).toString());
            }

        }
    }
} catch(Exception ex) {
    Toast.makeText(getApplicationContext(), ex.toString(), 4000).show();
}

it generates force closed

isSystemPackage() code is

private boolean isSystemPackage(ResolveInfo ri){
    return ((ri.activityInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM)!=0)?   
       true:false;
}

I tried to debug it but can't able to do it.


Got my Answer, This is for others to use this code.

 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());
          }

      }

cheers :)


Please try this approach. It works for me:

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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜