How to detect if an android app is a game?

前端 未结 3 1631
遇见更好的自我
遇见更好的自我 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<string> packageList = new List<string>();
    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);
        }
    }
    
    0 讨论(0)
  • 2020-12-11 10:35

    There is no automatical way to detect if an app is a game. You just could compaire the package name of the common part of the package name. My solution was to index the google store pages and hash the package names.

    I could optimize my hashes by building common prefixes. I handled the package name as a domain and grep the public suffix. I use the list from http://publicsuffix.org/.

    A "public suffix" is one under which Internet users can directly register names. Some examples of public suffixes are .com, .co.uk and pvt.k12.ma.us. The Public Suffix List is a list of all known public suffixes.

    The Public Suffix List is an initiative of Mozilla, but is maintained as a community resource. It is available for use in any software, but was originally created to meet the needs of browser manufacturers.

    With this list you can detect part of a packagename is a common prefix.

    0 讨论(0)
  • 2020-12-11 10:39

    This answer is deprecated!
    Correct and backwards compatible way to do this is here!

    Since Android API version 21, there's finally a way to check if an application is a game.

    PackageManager pm = mContext.getPackageManager();
    ApplicationInfo ai = pm.getApplicationInfo(mPackageName,0);
    if((ai.flags & ApplicationInfo.FLAG_IS_GAME) == ApplicationInfo.FLAG_IS_GAME)
        return true;
    return false;
    
    0 讨论(0)
提交回复
热议问题