简体   繁体   English

Android:applicationInfo.loadDescription()始终返回null

[英]Android: applicationInfo.loadDescription() always returning null

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. 我可以使用以下代码成功获取应用的标题,版本和图标,但由于某种原因,说明始终返回为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. App类只是一个bean类,仅设置为其赋予的值,仅此而已。 It is impossible that the error lies there, since I am indeed getting a "" for the description. 错误在那里是不可能的,因为我的描述的确是“”。 ie description is coming up as null for some reason. 即由于某种原因,描述以空值出现。

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. PackageManager从应用程序清单中读取任何内容。 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). 似乎大多数人(包括我)都没有这样做的理由,因为我不知道使用此描述的任何地方(除了事实之外,人们可以通过PackageManager查询它)。

To make that shure you could install a HelloWorld Application on your Phone or emulator, and provide a description inside its manifest. 为此,您可以在电话或仿真器上安装HelloWorld应用程序,并在其清单中提供说明。 You should get it with your code. 您应该使用您的代码来获得它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM