0

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.

  • 2
    Are you positive that the app(s) you are going through have a description? Most apps including all that I have wrote do NOT have one. The method returns null if no description is set. – Tom Jun 23 '12 at 19:07

1 Answers1

3

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.

Rafael T
  • 15,401
  • 15
  • 83
  • 144
  • Thanks! You were correct. It's just that I assumed at least official google/samsung/etc. apps would have a description but when they weren't showing any I assumed there was something wrong with my code. The only app out of the 300 I have that even has a description is Astro File Manager, that's it, nothing else. No worries, I guess it's a removable feature. Thanks again for the fast, thoughtful reply =) – Jasjit Singh Marwah Jun 23 '12 at 19:43