
As already
stated in the Intel blog , at the end of last year, Google released a new Nexus Player based on the Intel Atom processor. In this article you will find tips on how to adapt your Android application for this device in particular, and Android TV in general.
If you want your application to be accessible to Android TV devices and seen as a bootloader, you must firstly provide an activity that will process intent
action.Main for the category
LEANBACK_LAUNCHER , secondly, add TV-specific resources and, third, indicate that your application does not require a touchscreen display. As you can see, everything is very simple. Now let's see how it looks in practice.
Like the classic Android downloader, the Android TV downloader will search for the activity of your application that you specified in
android.intent.action.MAIN intent . But in the case of the Android TV downloader, the intent category will not be
android.intent.category.LAUNCHER , but rather
android.intent.category.LEANBACK_LAUNCHER .
Here is how you should declare the
Main Activity of your Android TV application:
')
AndroidManifest.xml: <activity android:name=".TvMainActivity" android:banner="@drawable/ic_banner" android:theme="@style/TvAppTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> </intent-filter> </activity>
Comment. There are two categories of applications in Leanback Launcher: Apps and Games. If you want to appear in the list of games, you need to set the isGame property to true:
AndroidManifest.xml: <application> ... android:isGame="true" ...>
At the top of a specific intent filter, also located in this activity, there is the android: banner property, which defines the banner that will be displayed in the launcher. The banner is a picture of 320x180 pixels, which should be placed in the drawable-xhdpi resource folder. The picture should include the name of your application (if necessary, localized) and not have an alpha channel:

All this will allow the application to be visible and run in Android TV launcher.
However, in order for the application to be compatible with Android TV, you also need to provide and declare support for Android devices without a touch screen. First of all, you need to implement navigation support using the crossbar (D-pad). The standard Android interface elements support it on their own, but in practice some configuration is required.
Specify the element to which the initial focus in your view will be sent using
requestFocus () in Java or
<requestFocus /> in the XML markup:
my_activity.xml: <View android:id="@+id/my_view" android:focusable="true" > <requestFocus /> </View>
The
android: focusable property must be
true if you want the focus request to work when the view is increased.
Sometimes you need to customize the navigation inside the view. You can choose how the focus will move from one element to another using the
nextFocus property:
my_activity.xml: <View android:nextFocusDown="@id/bottom_view" android:nextFocusUp="@id/top_view" android:nextFocusLeft="@id/left_view" android:nextFocusRight="@id/right_view" />
Once navigation using the D-pad works in your application, you can declare it in AndroidManifest.xml. Just declare that we don’t need touch capabilities:
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
Fulfilling the above requirements is enough for your application to be installed and run on Android TV. Now let's talk a little about the convenience of its use.
The design of the application should not contain menu bars and toolbars (even if the menu bar works with the D-pad, this is definitely a bad idea in terms of usability). Two themes that you can use are
Theme.Leanback from the Leanback and
android support library
: Theme.NoTitleBar . These topics do not include rims around the edges of the screen, so they should be added separately. Note that the Leanback elements of the field are already included.
<LinearLayout ... android:layout_marginTop="27dp" android:layout_marginLeft="48dp" android:layout_marginRight="48dp" android:layout_marginBottom="27dp" ...>
The Leanback support library is available starting at Level 17 API and contains ready-to-use elements and themes for applications. If you plan to support earlier versions of the API, you can store all links to themes and Leanback elements in the TV-specific part of the application and then use the gradle manifest merge function to avoid minSdkVersion upgrade:
AndroidManifest.xml: <manifest xmlns:tools="http://schemas.android.com/tools" ...> <uses-sdk tools:overrideLibrary="android.support.v17.leanback" /> ...
See
an example of using the Leanback support library. I also advise you to read a good
introductory article by Sebastiano Gottardo (musixMatch).
Android TV games can be significantly improved by adding multiplayer mode and gamepad support. In the manifest, you can specify that the game supports the gamepad:
<uses-feature android:name="android.hardware.gamepad" android:required="false" />
Set this option as required (required) only if the gamepad is required for your application; Remember that it is not included with the Nexus Player type of device. Additional Android devices can be used as controllers, but at the moment they can only act as a D-pad.
Explore a variety of game controllers can be on
this training .
The recommendation block takes up half the space in the launcher; to appear there, send a notification with the established recommendation category as described in the
official training .
Using the filtering system by functionality in the Play Store, you can limit the distribution of your application to only Android TV compatible devices by setting the desired value android.software.leanback:
AndroidManifest.xml: <uses-feature android:name="android.software.leanback" android:required="true" />
If required, your application will be available only to Android TV compatible devices.
You can distribute your application as a separate position in the Play Store, there is also an option to download it as a TV version of an existing application, using the
multiple APK function in the Play Store. In the second case, the TV version should have a different version Code than the classic application.
Nexus Player is a fully 64-bit platform and the core of the system, of course, is also 64-bit, but the user space remains today x86 32-bit. On the device, you can safely run the code compiled for ARM, but it is better to use x86 binaries. On aspects of compatibility for x86 devices can be found in my
previous article .
A summary of the principles of programming for Android TV can be found on the
website of Android-developers .
If
android: screenOrientation = ”portrait” is specified in any activity of your application, the
android.hardware.screen.portrait property will be forced to
true . You need to force it over to false in order for your application to be available for Android TV devices:
<uses-feature android:name="android.hardware.screen.portrait" android:required="false" />
The same is necessary for:
- android.hardware.location.android.permission.ACCESS_FINE_LOCATION
- android.hardware.camera.autofocus and android.hardware.camera implied by android.permission.CAMERA
- android.hardware.microphone implied by android.permission.RECORD_AUDIO
- android.hardware.telephony implied by various phone permissions
When your application is ready and ARK is uploaded to the Play Store developer page, you need to add a screenshot and a banner:

And put the necessary tick to request the distribution of the application on Android TV:

It will be checked before it appears in the Play Store, available for Android TV.