Setup for Android TV Apps

20 / Jun / 2016 by Ankit Kumar Jain 0 comments

Android TV development follows the same structure as other android apps like Android phones and tablets. We can modify an existing Android app to an Android TV app. Anybody with a good understanding of Android application development can create a TV app.

Prerequisites for Android TV App

  1. Android Development IDE (Android Studio)
  2. SDK Tool Verison : 24.0.0 or Higher
  3. SDK with Android 5.0 (API 21) or Higher

Main Components for Android TV App

Android TV Activity

An Android TV application must have a launcher activity for TV specifically in the manifest, using CATEGORY_LEANBACK_LAUNCHER intent filter. This filter specifies that this application is for TV and makes it available for the TV section of Google Play Store. This intent filter also works as the LAUNCHER intent filter in other android apps. When we click on the icon of our app on android TV then the particular activity will be launched.

The following code snippet shows how to add LEANBACK_LAUNCHER in the manifest file.

<application
  android:banner="@drawable/banner" >
  ...
  <activity
    android:name="com.ttntv.android.MainActivity"
    android:label="@string/app_name" >

    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>

  <activity
    android:name="com.ttntv.android.TvActivity"
    android:label="@string/app_name"
    android:theme="@style/Theme.Leanback">

    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
    </intent-filter>

  </activity>
</application>

In the above code, you’ll see there are 2 main activities. The second activity is launching on a TV device.

If we don’t include LEANBACK_LAUNCHER then this application will not be available for TV Apps on Google Play Store. If we try to launch the app using developer tools on TV devices without this filter then it will not be visible on TV device as well.

Declare Leanback support

We need to declare Leanback support in manifest required by Android TV application. If you want to run your application on Android devices like iPhones and tablets other than a TV, then set required as false.

<manifest>
    <uses-feature android:name="android.software.leanback"
        android:required="false" />
    ...
</manifest>

Declare TouchScreen not required

Applications running on TV do not require touchscreen support, so we need to declare the touchscreen feature as false. This setting identifies that your application is for TV, and your app is considered as a TV app in Google Play Store.

<manifest>
    <uses-feature android:name="android.hardware.touchscreen"
              android:required="false" />
    ...
</manifest>

Provide a home screen banner

Your application must provide a home screen banner image if it includes a Leanback launcher tag. Banner is the application launch point and it’s first visible when a user runs his application. Follow a design pattern while designing Banners.

<application
    ...
    android:banner="@drawable/banner" >

    ...
</application>

Add TV Support Libraries

  • v17 Leanback library – Provides user interface widgets for TV apps, particularly for apps that do media playback.
  • v7 Recyclerview library – Provides classes for managing the display of long lists in a memory efficient manner. Several classes in the v17 Leanback library depend on the classes in this library.
  • v7 Cardview library – Provides user interface widgets for displaying information cards, such as media item pictures and descriptions.

Although these libraries are highly recommended by Google for android TV app development, these are not necessary.

The only thing to keep in mind while adding v17 Leanback library is that you must include v4 support library as the Leanback library is dependent on v4.

Run TV Apps

Running your app is an important part of the development process. The AVD Manager in the Android SDK provides device definitions that allow you to create virtual TV devices for running and testing your applications.

To create a virtual TV device:

  1. Start the AVD Manager. For more information, see the AVD Manager help.
  2. In the AVD Manager dialog box, click the Device Definitions tab.
  3. Select one of the Android TV device definitions and click Create AVD.
  4. Select emulator options and click OK to create the AVD.

    Note: For best performance of the TV emulator device, enable the Use Host GPU option and where supported, use virtual device acceleration. For more information on hardware acceleration of the emulator, see Using the Emulator.

To test your application on the virtual TV device:

  1. Compile the TV application in your development environment.
  2. Run the application from your development environment and choose the TV virtual device as the target.

 

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *