An Introduction to Android TV

10 / Nov / 2015 by Bharat Ghimire 3 comments

This blog will introduce you to Android TV platform from what android TV is, How it is different from Android mobile development and finally how to create an Android TV app.

Note: This blog  is just the introduction to the Android TV  not a full coverage of Android TV development.

What is Android TV ?

Android TV was introduced in Google I/O 2014. It is the new service which allow google to enter into a totally new domain and it promise to make searching through on-demand as easy as pie and it is power by Google search.

Android TV comes in two variations first is built in and second you can add Android TV to your existing TV by purchasing a standalone set top box. Android TV is based on Android so your existing app for Android mobile and tablet also can run on Android TV. As per User point of view user can access Google Play Store for an Android TV app, movies or music and games.

How it is different to development Android TV app than mobile or tablet app ?

  1. TV is designed for 10-foot experience. As per official Android documentation, average viewer viewed TV about 10 feet away and it is much bigger than most of the other Android device, this type of screen does not provide the same level of precise detail and colour as other smaller device. For this reason, keep text to  a minimum and in place of text try to use image, voice over, sound and video to communicate with the user.
  2. Keep Interaction minimum and simple. TV is not a mobile device user used it for entertainment. TV usually control either by a remote control, game controller or an app in your mobile device which give user limited control over a TV. When developing an app for TV keep interaction to a minimum and avoid any complicated interaction.
  3. TV does not have a touch screen, TV controls are restricted to a directional pad and a select button. So when developing an app for TV you need to think about effective navigation.One way to do it by using ListView or GridView view, it is easy to navigate in these view group using direction pad and a select button.
  4. Screen orientation for TV must be Landscape. TV screen always displays on landscape mode. For an app which support both mobile devices and you want to convert it for TV and your project support android:screenOrientation=”portrait” the android.hardware.screen.portrait requirement by default set to true. This will only make your app visible for only those devices not for TV in play store. For making it visible, you have to set.
    <uses-feature
    android:name="android.hardware.screen.portrait"
    android:required="false" />
  5. In Android mobile app titlebar theme is standard user interface but its big no for TV. Google provide a LeanBack Library for TV user interface. If you are not using a LeanBack Library then add this to your activity to suppress titlebar.
    <application>
      <activity    
           android:name="com.demo.android.TvActivity"    
           android:label="@string/first_screen"    
           android:theme="@android:style/Theme.NoTitleBar">
      </activity>
    </application>
    
  6. Android TV does not have much hardware like other android devices.When your are developing an app for TV avoid to use following :
    • Near Field Communication (NFC)
    • Touchscreen
    • GPS
    • Camera
    • Microphone
    • Telephony


Steps to create Android TV App

First thing first,

  1. Update SDK tools to version 24.0.0 or higher.
  2. Update your SDK with 5.0(API 21) or higher this will provides you new APIs for TV apps.

Once you are done with updates

  1. Launch Android Studio
  2. Select Start a new Android Studio Project.
  3. Give it a name and domain for this blog we will give it a name First TV App and domain will be com.dummy, after this click Next or Press Enter.
    first screen
  4. Select TV, by default Phone and Tablet, is selected, deselect it if you only want to build an app for Android TV. We can also change the minimum SDK level by default it is API 21. After selecting minimum SDK, click Next.Add Activity to TV
  5. Select Android TV and press Next.
  6. Fill the given detail or leave it as default and click FINISH.Customize the Activity
  7. Finally we will get your Project
  8. Given below image will show you how your project structure lookalike.Project Structure

Now we will see how the Android TV manifest is different then Android Mobile or Tablet manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dummy.com.firsttvapp" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

Android TV need a permission for android.hardware.microphone as it need for voice search which every android TV had.

If your app does not required microphone then add these lines.

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

Android tv does not support touchscreen support so, your app should have these line to prevent touchscreen support.

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

By default when you create project your app is using leanback interface.

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

if you not want to use it make android:required :”false”

 <application
 android:allowBackup="true"
 android:icon="@mipmap/ic_launcher"
 android:label="@string/app_name"
 android:supportsRtl="true"
 android:theme="@style/Theme.Leanback" >
 <activity
 android:name=".MainActivity"
 android:banner="@drawable/app_icon_your_company"
 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>

By default Android TV use android theme=”@style/Theme.LeanBack”. android:supportsRtl=”true” implies that your application will be able to deal with RTL (right to left) layouts. If set to false (default value), your application will not care about RTL layouts.
Your activity should always in landscape mode for Android TV for that you have to set android:screenOrientation=”landscape” .

This intent filter implies the given activity is launcher activity also implies that if an app is open in Android TV this activity will act as a launcher activity.

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

Add this intent filter to the activity which you want to make a launcher for your app.

To test the app which you create follow the following steps

  1. Launch the AVD Manager by clicking the AVD Manager icon in the toolbar or go to Tools > Android > AVD Manager.
  2. If you already installed the emulator of Android TV you will see the option to launch android TV emulator like below image.If you did not install the emulator then follow step 3.
  3. Click Create Virtual TV and the select one of the Android TV devices listed.
  4. Select your system image and then click Next.
  5. Give your device a name and click FINISH.

Now you are down with installing now go back to your Android TV project and click Run icon on the toolbar or select Run> Run App.

Once your ADB finish with compiling and loading you will see your app in the emulator.

This article only gives you an introduction part of Android TV. There is a lot more to explore in Android TV platform. You can continue your development with learning these topics:
BrowseFragment.
DetailsFragment.
SearchFragment.

Thanks for reading this blog .
Happy Learning.
FOUND THIS USEFUL? SHARE IT

comments (3)

Leave a Reply to Manpreet Singh Cancel reply

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