Today’s guest tutorial comes to you courtesy of Greg Pugh, a Corona Ambassador, app developer, video tutorial instructor, children’s book author, and illustrator. Check out Greg’s site at GPAnimations.com for his tutorials and current games.
Corona Labs recently implemented support for the Android TV, a competitor to the Amazon Fire TV and Apple TV. Last year, Ed Maurina released a module that maps the controls to the Amazon Fire TV, so I’ve taken his code and modified it for the Android TV controller. I’m going to show you how you can implement the Android TV game controller button events into your game so you can upload it to the Google Play Store.
First, download the source folder from Dropbox. In this folder, you’ll see a file named
RGEasyFTV.lua. This is Ed’s FireTV controller code that I’ve edited. If you open it, you’ll see the code numbers for the Android Game Controller.
-- Android TV code mappings
if ( onFTV ) then
codes = 'up'
codes = 'down'
codes = 'left'
codes = 'right'
codes = 'back'
codes = 'menu'
codes = 'a'
codes = 'b'
codes = 'x'
codes = 'y'
Since these are mapped for you here, you’ll only need to reference the buttons by their names in your code (e.g.
keyName == 'a').
build.settings file, you see that I’ve set
supportsTV to be
supportsTV line is essential making your app compatible with the Android TV — without this line of code, your app can still be approved for Google Play, but it will not show up as compatible with the customer’s Android TV devices.
Screen1.lua, you’ll see the following code:
local function onFTVKey( event )
if ( enableListener == false ) then return false end
local keyName = event.keyName
if ( event.phase == "began" ) then
elseif( event.phase == "ended" ) then
if ( keyName == 'a' ) or ( keyName == 'right' ) then
listen( "onFTVKey", onFTVKey )
This is the function I use to control the app using the Android TV game controller. You’ll notice that I give the option to either use either the directional pad or the A button. The great part about Ed’s
RGEasyFTV.lua file is that it enables you to use your computer’s keyboard to test the app as you’re developing it. So, either the right arrow or the A key on your keyboard can be used until your install it on an actual Android TV.
Two additional pieces of artwork that you’ll need to include for an Android TV app are a 320×180
Banner-xhdpi.png file and a screenshot of how it will look on a TV screen that you’ll add to your app profile on Google Play.
Once your events are coded to game controller input, you can build the app for Google Play:
Next, using your developer cable, hook your Android TV to your computer via the USB port and make sure the device is hooked up to a TV and powered on. On my MacBook, I dragged the exported
AndroidTVTutorial.apk file into
In the Terminal/console, I changed the directory to
platform-tools, found my Android TV device, and installed
AndroidTVTutorial.apk onto it:
Now the app is available to play on Android TV:
Once you’ve tested it, you can upload it to Google Play and, if you’ve done everything correctly, your app will now be Android TV compatible!