First, download the https://www.dropbox.com/s/h8s5v2xrtpkhpb3/AndroidTVTutorial.zip?dl=0 source directory here.
The directory can be found Rgeasyftv.lua, open can see below corresponds to the Android TV game controller (remote control? ) button's code:
--Android TV Code Mappingsif(ONFTV) Thencodes[ +] =' up'codes[ -] =' Down'codes[ +] =' Left'codes[ A] =' Right'codes[4] =' Back'codes[ the] ='Menu'codes[ the] ='a'codes[ the] ='b'codes[ About] ='x'codes[ -] ='y'
Since this mapping has been done for you, you only need to refer to the code by name, for example: KeyName = = ' a '.
In the build.setting file, you need to set SUPPORTSTV to true, and isgame to true. This SUPPORTSTV setting makes your app adaptable to Android TV. If you don't add this setting, your app can still be submitted to Google Play, but it won't show up on your customer's Android TV device.
In the Screen1.lua file, you can see the following code:
Local functionOnftvkey (Event)if(Enablelistener = =false) Then return false End LocalKeyName =Event.keynameif(Event.phase = ="began") Then ElseIf(Event.phase = ="ended") Then if(KeyName = ='a')or(KeyName = =' Right') ThenonScreen2 ()End End return trueEndListen ("Onftvkey", Onftvkey)
This is an Android TV game controller to control the application of the code, you can see here is mainly for a direction key and a key. Another benefit of the Rgeasyftv.lua file is that you can test your app by using your computer's keyboard instead of the game controller during your development period.
There are two other important things:
1 You need to include a 320x180 banner-xhdpi.png file in your app.
21 What you need to provide when adding apps to Google Play how your app works on TV.
Once the event code used to receive the game control input is written, you can create an app for Google Play.
Next, use your developer cable to connect your Android TV and your PC with USB to make sure the connection is up and running. On your MacBook, we drag the exported androidtvtutorial.apk to Android->sdk->platform-tools.
In the console, we change the directory to Platform-tools, locate our adroid TV device, and then install androidtvtutorial.apk in.
At this point, your app can run on Android TV.
Coronasdk Create Androidtv app