How to get Category for each App on device on Android?
android, google-play
Solution
I know that this is an old post, but for anyone still looking for this, API level 26 (O) has added categories to `android.content.pm.ApplicationInfo`.
From the docs 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`
One can now do something like:
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)
// ...
}
Problem
I've got an Android app which scans for all Apps installed on the device and then reports this to a server (it's an MDM agent). Any suggestions on how to get the Category of the App? Everyone has a different list of Categories, but basically something like Game, Entertainment, Tools/Utilities, etc. From what I can tell there is nothing related to Category stored on the device itself. I was thinking of using the android market API to search for the application in the market and use the Category value returned by the search. Not sure how successful this will be finding a match. Any suggestions on how best to do this? Any suggestions on a different approach? Thanks in advance. mike