Android TV – Introduction

Today we will learn the Android TV platform, from what it is and what are the characteristics of an effective TV app. We will see each from creating and testing of your very own Android TV sample application.

First let’s see what Android TV is actually. It was announced at Google IO 2014, and is the new smart TV platform from Google. You can either purchase a TV with the new platform built in, or can add Android TV to your existing TV by purchasing a standalone set-top box.

If you are an experienced developer for Android smartphones or tablets, you will easily be familiar with Android TV. You just need to be aware of some major differences I will cover in this tutorial that makes Android TV unique.

As per the official Android TV documentation, an average TV viewer sits around 10 feet away from their screen, so all your content must be clearly visible from 10 feet away. The trick is to design a user interface that re-sizes automatically, according to the size of the TV screen.

You also need to minimize the text because the text becomes more difficult to read from a distance. To achieve Less text’s goal you will need to communicate with your users via some other methods, like voice-over, sound effects, video, images etc.

Most likely you should use android TV for apps which are used to display videos and images etc., which needs minimal text and are mostly given better results on big screen.

Check out the below video published by google developers on why they introduced Android TV

Before starting, developing anything for the Android TV , make sure to update your SDK to Android 5.0 (API 21) or higher, and your SDK tools to version 24.0.0 or higher because the lower version won’t support it.

If you are already up to date, it’s time to build your first Android TV app. Follow the steps described below:

Step1: Create a new Android Project and follow the steps by clicking Next.

Step2: Select TV, instead of Phone/Tablet when asked to choose the minimum SDK. Although you can create Android TV projects that have a smartphone, tablet and/or Android Wear module support, but to make it a simple check TV only at this stage.

Step3: Enter Android TV Activity and other details as below:

androidtv1

Let it be the with default values and click Finish.

Step4: You will see below the code in your manifest which is different from your normal mobile manifest:

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myandroidtv" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

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

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Leanback" >
<activity
android:name=".MainActivity"
android:icon="@drawable/app_icon_your_company"
android:label="@string/app_name"
android:logo="@drawable/app_icon_your_company"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DetailsActivity" />
<activity android:name=".PlaybackOverlayActivity" />
<activity android:name=".BrowseErrorActivity" />
</application>

</manifest>

 

The android.permission.RECORD_AUDIO permission implies that this app requires android.hardware.microphone. So this line of code effectively prevents your app from being installed on devices that don’t have access to a microphone.

If your app can run without microphone, you can add following code in your manifest:

 

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

 

Above code allow users to install your app on devices that don’t have access to microphone.

Your Android TV app must declare that it doesn’t require touchscreen support by adding below code in manifest.

 

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

 

App banners represent your app on the Android TV homescreen and are the way user launches your app. It must be a 320×180 image and with app name as text.

Step5: Along with above new changes in your manifest the default android TV app comes with three layout xmls and some activities in your project folder as shown in image below:

1.) activity_main
2.) activity_detail
3.) playback_controls

androidtv11

Step6: Create a Android TV AVD and launch it to see the results:

androidtv2

You must have HAX Ram higher then the space required to launch TV emulator on your system. Go to AndroidsdkextrasintelHardware_Accelerated_Execution_Manager and run HAX application to change RAM size if you won’t be able to launch you TV emulator.

Check my previous blog on Video Cropping.

Leave a Comment: