Declare support for game controllers on Android TV

We have an app which is already available on phones/tablets, and now has TV support. However it needs a gamepad rather than a remote, and we’ve noticed that there are some games on the store which say “gamepad required” when you view them in the store.

Google’s docs say there is a android.hardware.gamepad feature which can be added to the manifest:

http://developer.android.com/training/tv/games/index.html#manifest

Is there a way to add this flag to the manifest (we are building this particular app using the simulator, NOT enterprise)? I’ve added the supportsTV and isGame properties to my build.settings file, but not sure if there is anything else I need to add for the game controller to be required.  

Also, would this feature only be applied on TV devices? We would prefer to have one apk which can be used on mobile and TV, with the mobile devices using multitouch and the TV devices using a gamepad.

Check out our PewPew sample code, which has some flushed out build.settings and art assets to work on Android TV/Ouya/Apple TV.

Specifically, I think you’re missing the usesFeatures setting and should see our docs and Android’s <uses-feature> documentation.

It is not tv-specific, you’d have to build two APKs for that. But, you likely shouldn’t! Devices like the NVIDIA Shield use controllers, and if your app supports them it would be boon to not turn off controller support.

For our other apps I tend to use Enterprise, so I’d forgotten all about the uses-feature table in build.settings.

Just so I’m clear, if I add the:

{ name="android.hardware.gamepad", required=false },

to my build.settings the game won’t “stop working” on devices without a gamepad (because required=false), and it will say “gamepad required” when it’s displayed on an Android TV device?

Also, if I have this as well: 

mainIntentFilter = { categories = { "android.intent.category.LEANBACK\_LAUNCHER", }, }

will the app continue to function as normal on devices that do not use the Leanback Launcher?

I’m not 100% certain that you’ll get a “gamepad required” text on Google Play for Android TV with required set to false. Even with an Enterprise/native project you’d need two separate apps to have two separate Android Manifests.

Devices without Leanback Launcher should ignore the related setting.

You are correct about setting “android.hardware.gamepad” required=false.  That tells the Android app store that your app supports gamepads, but does not require them.  This way, your app will still be downloadable on phones and tablets.  And Corona already automatically sets up the manifest to not require touchscreen support either when you build your app for Android TV.

   http://developer.android.com/training/tv/games/index.html#manifest

Regarding the LEANBACK_LAUNCHER, you do *not* need to add that to your “build.settings” file.  Corona automatically adds that for you.  Go ahead and get rid of that.

Ah, I assumed that the leanback bit was not automatically added, because it doesn’t show up in my launch args when I launch the app.

I tried following your advice from this older post:
https://forums.coronalabs.com/topic/56373-is-there-a-model-parameter-for-systemgetinfo-that-covers-all-android-tv-devices/

but the leanback intent is not listed.

The “LEANBACK_LAUNCHER” is definitely added to your manifest.  It has to be or else you would not be able to launch your app on an Android TV.  We automatically inject it if you set “supportsTV” to true.

It’s an intent-filter “category”.  So, look under the category table.  I don’t know if Android will push that category into your launch intent, but it’s definitely in the resulting AndroidManifest.xml file.

Check out our PewPew sample code, which has some flushed out build.settings and art assets to work on Android TV/Ouya/Apple TV.

Specifically, I think you’re missing the usesFeatures setting and should see our docs and Android’s <uses-feature> documentation.

It is not tv-specific, you’d have to build two APKs for that. But, you likely shouldn’t! Devices like the NVIDIA Shield use controllers, and if your app supports them it would be boon to not turn off controller support.

For our other apps I tend to use Enterprise, so I’d forgotten all about the uses-feature table in build.settings.

Just so I’m clear, if I add the:

{ name="android.hardware.gamepad", required=false },

to my build.settings the game won’t “stop working” on devices without a gamepad (because required=false), and it will say “gamepad required” when it’s displayed on an Android TV device?

Also, if I have this as well: 

mainIntentFilter = { categories = { "android.intent.category.LEANBACK\_LAUNCHER", }, }

will the app continue to function as normal on devices that do not use the Leanback Launcher?

I’m not 100% certain that you’ll get a “gamepad required” text on Google Play for Android TV with required set to false. Even with an Enterprise/native project you’d need two separate apps to have two separate Android Manifests.

Devices without Leanback Launcher should ignore the related setting.

You are correct about setting “android.hardware.gamepad” required=false.  That tells the Android app store that your app supports gamepads, but does not require them.  This way, your app will still be downloadable on phones and tablets.  And Corona already automatically sets up the manifest to not require touchscreen support either when you build your app for Android TV.

   http://developer.android.com/training/tv/games/index.html#manifest

Regarding the LEANBACK_LAUNCHER, you do *not* need to add that to your “build.settings” file.  Corona automatically adds that for you.  Go ahead and get rid of that.

Ah, I assumed that the leanback bit was not automatically added, because it doesn’t show up in my launch args when I launch the app.

I tried following your advice from this older post:
https://forums.coronalabs.com/topic/56373-is-there-a-model-parameter-for-systemgetinfo-that-covers-all-android-tv-devices/

but the leanback intent is not listed.

The “LEANBACK_LAUNCHER” is definitely added to your manifest.  It has to be or else you would not be able to launch your app on an Android TV.  We automatically inject it if you set “supportsTV” to true.

It’s an intent-filter “category”.  So, look under the category table.  I don’t know if Android will push that category into your launch intent, but it’s definitely in the resulting AndroidManifest.xml file.