简体   繁体   English

Android:确定已安装应用的类别

[英]Android: Determine category of installed apps

Given the list of installed packages on an Android device, is there a way to sort the applications into categories without using a self-compiled hard-coded list of apps in categories? 鉴于Android设备上已安装的软件包列表,是否有办法将应用程序分类,而不使用类别中自编译的硬编码应用程序列表?

For example, if the installed apps were Phone, Angry Birds & Messages, Phone & Messages might be in Communications and Angry Birds in Games. 例如,如果安装的应用程序是电话,愤怒的小鸟和消息,电话和消息可能在通信和愤怒的小鸟在游戏中。

I've seen How to get Category for each App on device on Android? 我已经看过如何在Android上的设备上获取每个应用程序的类别? yet hoped there may be a method that has come along since. 但希望可能有一种方法随之而来。

No, because apps don't have categories. 不,因为应用没有类别。 Apps don't need to be installed through google play, the categories on other stores won't be the same. 不需要通过Google Play安装应用,其他商店的类别也不一样。 It may never have been installed from a store to begin with- I sideload apps all the time written by myself or friends. 它可能永远不会从商店安装开始 - 我总是自己或朋友写的应用程序。 Th concept doesn't exist. 这个概念不存在。

Not to mention Google Play categories are pretty bad- things frequently don't fall into one or the other, the descriptions are vague, and they're way too broad- they need at least 2 or 3 levels of subcategories to make them halfway usable. 更不用说谷歌播放类别非常糟糕 - 事情往往不属于其中一种,描述含糊不清,而且它们太宽泛 - 它们需要至少2或3个子类别才能使它们中途使用。

There is no change API wise since the last question. 自上一个问题以来,API没有变化。

At best, you could retrieve each package name and scrape the Google Play page. 最多,您可以检索每个包名称并抓取Google Play页面。 However, this will fail if the app is not present on Google Play. 但是,如果Google Play上没有该应用,则会失败。

I also faced the same issue. 我也遇到了同样的问题。 The solution for the above query is stated below. 上述查询的解决方案如下所述。

Firstly, download the Jsoup library or download the jar file. 首先,下载Jsoup库或下载jar文件。

or Add this to your build.gradle(Module: app) implementation 'org.jsoup:jsoup:1.11.3' 或者将它添加到你的build.gradle(Module:app)实现'org.jsoup:jsoup:1.11.3'

private class FetchCategoryTask extends AsyncTask {
private final String TAG = FetchCategoryTask.class.getSimpleName();
private PackageManager pm;

@Override
protected Void doInBackground(Void... errors) {
  String category;
  pm = getPackageManager();
  List<ApplicationInfo> packages = 
  pm.getInstalledApplications(PackageManager.GET_META_DATA);
  Iterator<ApplicationInfo> iterator = packages.iterator();
  //  while (iterator.hasNext()) {
  // ApplicationInfo packageInfo = iterator.next();
  String query_url = "https://play.google.com/store/apps/details? 
  id=com.imo.android.imoim";  //GOOGLE_URL + packageInfo.packageName;
  Log.i(TAG, query_url);
  category = getCategory(query_url);
  Log.e("CATEGORY", category);

  // store category or do something else
  //}
  return null;
 }
private String getCategory(String query_url) {
  try {
     Document doc = Jsoup.connect(query_url).get();
     Elements link = doc.select("a[class=\"hrTbp R8zArc\"]");
     return link.text();
      } catch (Exception e) {
    Log.e("DOc", e.toString());
     }
  }
} 

In return, you will get Application Company Name and category of the application 作为回报,您将获得应用程序公司名称和应用程序的类别

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

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