How to detect if an android app is a game?

前端 未结 3 1630
遇见更好的自我
遇见更好的自我 2020-12-11 09:54

In an app I am developing I need to iterate through the installed apps and detect which ones are games. Is there any way to do this?

I was thinking to a Play Store

3条回答
  •  囚心锁ツ
    2020-12-11 10:30

    For me the above answer didn't work, the ApplicationInfo.FLAG_IS_GAME is now deprecated, with API 28+ (in my case), you can do something like this:

    _pm = _context.PackageManager;
    List packageList = new List();
    Intent intent = new Intent(Intent.ActionMain);
    intent.AddCategory(Intent.CategoryLeanbackLauncher); // or add any category you want
    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);
        }
    }
    

提交回复
热议问题