android - 如何获取 Android 设备上每个应用程序的类别?

标签 android google-play

我有一个 Android 应用程序,它可以扫描设备上安装的所有应用程序,然后将此报告给服务器(它是一个 MDM 代理)。关于如何获取应用程序类别的任何建议?每个人都有不同的类别列表,但基本上是游戏、娱乐、工具/实用程序等。

据我所知,设备本身没有存储与类别相关的内容。我在考虑使用android market API来搜索市场中的应用程序并使用搜索返回的Category值。不确定这将如何成功地找到匹配项。关于如何最好地做到这一点有什么建议吗?

对不同的方法有什么建议吗?

提前致谢。 麦克

最佳答案

我知道这是一篇旧文章,但对于仍在寻找这篇文章的人来说,API 级别 26 (O) 已将类别添加到 android.content.pm.ApplicationInfo

来自文档 https://developer.android.com/reference/android/content/pm/ApplicationInfo#category :

public int category

The category of this app. Categories are used to cluster multiple apps together into meaningful groups, such as when summarizing battery, network, or disk usage. Apps should only define this value when they fit well into one of the specific categories.

Set from the R.attr.appCategory attribute in the manifest. If the manifest doesn't define a category, this value may have been provided by the installer via PackageManager#setApplicationCategoryHint(String, int). Value is CATEGORY_UNDEFINED, CATEGORY_GAME, CATEGORY_AUDIO, CATEGORY_VIDEO, CATEGORY_IMAGE, CATEGORY_SOCIAL, CATEGORY_NEWS, CATEGORY_MAPS, or CATEGORY_PRODUCTIVITY

现在可以做类似的事情:

PackageManager pm = context.getPackageManager();
ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, 0);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
    int appCategory = applicationInfo.category;
    String categoryTitle = (String) ApplicationInfo.getCategoryTitle(context, appCategory)
    // ...
}

关于android - 如何获取 Android 设备上每个应用程序的类别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10710442/

相关文章:

java - 使用keytool获取证书的MD5签名

android - Tesseract 在 android 中的最大识别时间

java - 如何使用Firestore向文档中的 HashMap 数组添加数据?

android - 上传到 google play 时出现 aapt 错误

reactjs - 在 Google Play 上更新使用 PWA2APK 构建的 PWA 应用程序时出现问题

android - 使用 relativelayout 对齐在中心对齐的 2 行控件

android - 如何将xml数据存入sqlite数据库

android - 谷歌开发者控制台 : How to see all ratings in review list?

android - Google Play 发布商帐户已终止,其他开发者可以发布我的应用吗?

android - 购买应用时 Google Play 未经许可的响应