3

Here it is described, how to get a list of all installed apps on Android by using the PackageManager.

I would like to get this complete list, filtered by all installed "Games". How can I filter all installed apps for category "Games"

Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103
  • As far as I know, Android makes no distinction between"App" and "Game". They are all apps. All you can do is maintain your own database of app package IDs which you know belong to games and use that to filter. – Alexander Hoffmann Nov 04 '21 at 16:11

1 Answers1

0

You need to parse each app web page to get its genre then sperate games genres from apps genres.

you could use Jsoup Java HTML Parser and here is a sample code

public class MainActivity extends AppCompatActivity {

public final static String GOOGLE_URL = "https://play.google.com/store/apps/details?id=";
public static final String ERROR = "error";

...


   private class FetchCategoryTask extends AsyncTask<Void, Void, Void> {

       private final String TAG = FetchCategoryTask.class.getSimpleName();
       private PackageManager pm;
       private ActivityUtil mActivityUtil;

       @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 = GOOGLE_URL + packageInfo.packageName;
               Log.i(TAG, query_url);
               category = getCategory(query_url);
               // store category or do something else
           }
           return null;
        }


        private String getCategory(String query_url) {
           boolean network = mActivityUtil.isNetworkAvailable();
           if (!network) {
               //manage connectivity lost
               return ERROR;
           } else {
               try {
                   Document doc = Jsoup.connect(query_url).get();
                   Element link = doc.select("span[itemprop=genre]").first();
                   return link.text();
               } catch (Exception e) {
                   return ERROR;
               }
           }
        }
    }  
}

you will find something like

<a class="r2Osbf" href="/store/apps/category/GAME_RACING" title="Racing">Racing</a>
...
"applicationCategory":"GAME_RACING"

So if the category contains "Game" text then it is a game.

Update: check this out

screenshot1

user16930239
  • 6,319
  • 2
  • 9
  • 33
  • Didi not work. A REST-Call per GET to e.g. https://play.google.com/store/apps/details?id=com.CrazyMonkeyStudios.Hidden responded with 200 success, but neither "a class r20sbf" nor "applicationCategory" included – Ralf Wickum Nov 08 '21 at 10:17
  • please see the updated answer with the image – user16930239 Nov 08 '21 at 11:04