There is a way to check this since API level 21 and it has recently changed in API level 26. These are the correct backwards compatible ways to do this.
Java:
public static boolean packageIsGame(Context context, String packageName) {
try {
ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return info.category == ApplicationInfo.CATEGORY_GAME;
} else {
// We are suppressing deprecation since there are no other options in this API Level
//noinspection deprecation
return (info.flags & ApplicationInfo.FLAG_IS_GAME) == ApplicationInfo.FLAG_IS_GAME;
}
} catch (PackageManager.NameNotFoundException e) {
Log.e("Util", "Package info not found for name: " + packageName, e);
// Or throw an exception if you want
return false;
}
}
Kotlin:
fun packageIsGame(context: Context, packageName: String): Boolean {
return try {
val info: ApplicationInfo = context.packageManager.getApplicationInfo(packageName, 0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
info.category == ApplicationInfo.CATEGORY_GAME
} else {
// We are suppressing deprecation since there are no other options in this API Level
@Suppress("DEPRECATION")
(info.flags and ApplicationInfo.FLAG_IS_GAME) == ApplicationInfo.FLAG_IS_GAME
}
} catch (e: PackageManager.NameNotFoundException) {
Log.e("Util", "Package info not found for name: " + packageName, e)
// Or throw an exception if you want
false
}
}
Source: Android Documentation