0

I got this code:

_pm = _context.PackageManager;
List<string> packageList = new List<string>();
Intent intent = new Intent(Intent.ActionMain);
intent.AddCategory(Intent.CategoryLeanbackLauncher);
var list = _pm.QueryIntentActivities(intent, PackageInfoFlags.MetaData);
var counter = 0;
foreach (var app in list)
{
    counter++;
    ApplicationInfo ai = _pm.GetApplicationInfo(app.ActivityInfo.PackageName, 0);
    if (filter.Equals(IApplicationsControl.Filter.AppsOnly))
    {
        if (ai.Category != ApplicationCategories.Game)
        {
            Android.Util.Log.Debug("pm", counter + ". " + ai.Category + " - " + app.ActivityInfo.PackageName);
            packageList.Add(app.ActivityInfo.PackageName);
        }
    }
}

The output:

1. Undefined - com.android.vending
2. Undefined - com.google.android.youtube.tv
3. Undefined - com.myApp.test1
4. Undefined - com.android.traceur
5. Undefined - com.arris.android.stb.rcu
6. Undefined - com.arris.upgradetest
7. Undefined - com.clearchannel.iheartradio.application.tvapplication
8. Undefined - com.ericsson.tv
9. Audio - com.google.android.music
10. Undefined - com.google.android.play.games
11. Undefined - com.uei.uassample
12. Undefined - com.FDGEntertainment.redball4.gp       <--- this is a game
13. Undefined - com.fgol.HungrySharkEvolution       <--- this is a game
14. Undefined - com.hyperkani.bomberfriends       <--- this is a game
15. Undefined - com.madfingergames.deadtrigger2       <--- this is a game
16. Undefined - com.secretexit.turbodismount       <--- this is a game
17. Undefined - com.vectorunit.purple.googleplay

I installed several games, such as Hungry Shark and DeadTrigger2, I opend the APKs and both applications got the isGame:true set in their AndroidManifest.xml files.

The code above is listing the categories of my apps as Undefined, this includes my 2 games, it's like that for nearly all of my apps, except some AUDIO app that plays music.

So, in the end, why does my code not work?

I was following this links:

How to check if the app is game or not programmatically?

Also, I found this one, that concerns me a lot:

How can check app is game or not android?

So in the end, is it even possible now to check if an app is a game or not?

My API lvl is 28+

Elydasian
  • 2,016
  • 5
  • 23
  • 41
  • The best approach here is to maintain your own database which includes the package names of known games. Then check if the found package names are in this database. – Alexander Hoffmann Jun 16 '20 at 13:51
  • So, you are telling me, that the second link I posted is true, and that there is no way to check if an app is a game. Is it mby possible to read the manifest file of an installed app? – Elydasian Jun 16 '20 at 13:55
  • No, I don't know if checking programatically works or not. But I would instead evaluate if it's feasibble to use the database approach since this approach doesn't rely on future API changes. The game flag might become inaccessible. And: Querying all packages has JUST been changed in Android 11: https://developer.android.com/preview/privacy/package-visibility#all-apps – Alexander Hoffmann Jun 16 '20 at 13:59

1 Answers1

1

Ofcourse, I searched 2 days without an answer, and then finally decided to post a question here, and ofcourse now i found an answer.

_pm = _context.PackageManager;
List<string> packageList = new List<string>();
Intent intent = new Intent(Intent.ActionMain);
intent.AddCategory(Intent.CategoryLeanbackLauncher);
var list = _pm.QueryIntentActivities(intent, PackageInfoFlags.MetaData);
foreach (var app in list)
{
    ApplicationInfo ai = _pm.GetApplicationInfo(app.ActivityInfo.PackageName, 0);
    var allFlags = ai.Flags;
    if (allFlags.HasFlag(ApplicationInfoFlags.IsGame))
    {
        packageList.Add(app.ActivityInfo.PackageName);
    }

}

What did I do? I saw, out of pure luck, that the ApplicationInfo variable ai, got a field Flags, that contain the correct flag, (not the flag FLAG_IS_GAME nor ApplicationCategories.Game)) also, I found the right class to pick the IsGame from (ApplicationInfoFlags.IsGame)

The rest is simple.

The conclusion, is that the approach to get the information about the app beeing a game or not about the category, or the FLAG_IS_GAME seems not to work as it should.

This worked for me, and hopefully the next guy in the same problem :)

Elydasian
  • 2,016
  • 5
  • 23
  • 41