How to get Category for each App on device on Android?

前端 未结 7 1942
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 04:25

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

7条回答
  •  囚心锁ツ
    2020-12-03 04:44

    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.

    or Add this to your build.gradle(Module: app) implementation 'org.jsoup:jsoup:1.11.3'

    private class FetchCategoryTask extends AsyncTask {
    
        private final String TAG = FetchCategoryTask.class.getSimpleName();
        private PackageManager pm;
        //private ActivityUtil mActivityUtil;
    
        @Override
        protected Void doInBackground(Void... errors) {
            String category;
            pm = getPackageManager();
            List packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
            Iterator 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

提交回复
热议问题