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 ?
- 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.
- 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.
- 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.
- 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" />
- 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>
- 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)
Steps to create Android TV App
First thing first,
- Update SDK tools to version 24.0.0 or higher.
- 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
- Launch Android Studio
- Select Start a new Android Studio Project.
- 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.
- 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.
- Select Android TV and press Next.
- Fill the given detail or leave it as default and click FINISH.
- Finally we will get your Project
- Given below image will show you how your project structure lookalike.
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
- Launch the AVD Manager by clicking the AVD Manager icon in the toolbar or go to Tools > Android > AVD Manager.
- 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.
- Click Create Virtual TV and the select one of the Android TV devices listed.
- Select your system image and then click Next.
- 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: