Question

I can successfully get the title, version and icon of an app using the code below but for some reason the description is always returned as null. Any help is appreciated.

Relevant Code:-

List<PackageInfo> packs = packageManager.getInstalledPackages(0);

  for(int i=0; i < packs.size(); i++) {
     PackageInfo p = packs.get(i);
     // skip system apps if they shall not be included
     if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1)) {
        continue;
     }
     App app = new App();
     app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
     app.setPackageName(p.packageName);
     app.setVersionName(p.versionName);
     app.setVersionCode(p.versionCode);
     CharSequence description = p.applicationInfo.loadDescription(packageManager); //error here?
     app.setDescription(description != null ? description.toString() : "");
     apps.add(app);
  }

The App class is just a bean class that just sets the values given to it, nothing more. It is impossible that the error lies there, since I am indeed getting a "" for the description. i.e. description is coming up as null for some reason.

Was it helpful?

Solution

There seems to be anything ok with your code. Your assumption, that any App has a description seems the "error" in this case. The PackageManager reads anything out of the Manifest of the App. Any developer of an App is free to provide a description to it. It seems that most of them (including me) don't see a reason to do that, because I do not know any place where this description is used (beside the Fact that one may query it through PackageManager).

To make that shure you could install a HelloWorld Application on your Phone or emulator, and provide a description inside its manifest. You should get it with your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top