1. Getting Started
Electronic supplementary material
The online version of this chapter (doi: 10.1007/978-1-4842-1784-9_1 ) contains supplementary material, which is available to authorized users.
As we all know, technology is constantly progressing in every aspect of our lives. With the explosion of smart phones and tablets, it was only a matter of time before televisions joined the fray as one of the next connected smart devices. While interactive televisions have been around for a few years, major contenders have only recently entered the market, with Android TV having been introduced in June of 2014 (albeit after the failed attempt of Google TV and the huge success of Chromecast), and Apple TV finally opening their platform to app developers in September of 2015. Given this, now is the perfect time to prepare for the next trend in app development by expanding your skillset with Android TV.
What Exactly Is Android TV?
Android TV is an interactive television platform developed by Google and released at its I/O conference in 2014. Taking what Google had learned from one of their previous attempts at entering the living room, known as Google TV, they created this operating system to be easily embedded in television sets or to allow traditional dumb TVs to become interactive TVs through the use of standalone set-top boxes. The new platform is a version of Android that has been optimized for television, and has access to all of the features developers are already familiar with, as well as some additional components provided through the Leanback Support library.
In addition to being able to create native applications for Android TV, the operating system also provides support for Google Cast. Google Cast is familiar to most people as the technology behind the Chromecast. This means that if your existing application supports casting, then users will still be able to use it with the Android TV, though without the full immersive experience provided by having a native Android TV app. While understanding how to develop cast enabled apps is useful, this book will focus on developing native apps for Android TV.
What to Expect from this Book
This book is intended to get you started with the Android TV platform so that you can extend existing apps or create your own to improve the living room experience of your users. You should have a basic understanding of Android development, as you will be working with adapters, fragments, activities, views, and other standard Android components. Anything covered that has been specifically introduced for Android TV will be discussed in this book, so no previous knowledge of those components is required. As you work through this book, you will create a relatively simple Android TV media application by writing each of the components in order to fully understand how the application operates. You will also build a couple of small example programs that emphasize additional APIs, such as LAN communication and reading input from the game controller, so you can start to build other applications such as games and utility programs. Along the way you will learn design concepts related to what makes the user experience different on a television compared to smart phones and tablets.
By the time you finish reading this book, you should have a firm grasp on the vocabulary associated with Android TV. Not only will you be able to create apps for the platform, but you should also be able to confidently seek out answers to your more complicated questions by understanding what you are looking for when searching through forums and the extensive, well-written Android documentation from Google.
Getting Set Up
One of the nice things about developing for Android is that the development tools can be used on most modern computer platforms, and Android TV development is no different. For coding the examples in this book, you will need a computer running Windows, Mac OS X, or Linux. This book will focus on using Android Studio as the development environment, which itself currently requires the Java Runtime Environment (JRE) and Java Development Kit (JDK). If you do not already have Android Studio, you can get it and find the official system requirements, including minimum operating system versions, for Android development by visiting https://developer.android.com/sdk/index.html , downloading Android Studio, and following the installation instructions for your operating system. At the time of this writing, the latest version of Android Studio is 1.4. During the installation process you will need to install the platform tools and APIs for at least Android 5.0 (Lollipop).
Creating a New Android TV Project
Once you have installed and set up Android Studio, you can create a sample project using the base Android TV template provided by Google. Do this by opening Android Studio and clicking on Start a New Android Studio Project under the Quick Start header.
When you arrive on the Configure Your New Project screen, set the Application Name to Hello World, the Company Domain to apress.com , and your Project Location to wherever you want to save your source code (see Figure ). Once you have filled in all of the required information, click Next and you will be taken to a screen to select which form factors your app will support.
Figure 1-1.
Configure your new project screen
For your Hello World application, unselect the check box next to Phone and Tablet and activate the check box next to TV. While you may have a module in your project for supporting phones and tablets, we will ignore that case for the sake of simplicity in this book. The minimum API version you will need for Android TV is at the oldest 21 (Lollipop), as Android TV was introduced with Lollipop. Figure shows what your target Android devices screen should look like before continuing on.
Figure 1-2.
Screen for selecting form factors supported by your app
When you click Next, youll be taken to a screen that asks whether you want to create an empty project or a default Android TV activity, as shown in Figure . For this sample, choose the Android TV Activity option.
Figure 1-3.
Selecting an Android TV template
The next screen you encounter will give you the option of renaming the activities, fragments, and layout files in the sample Android TV application (Figure ). For this example, you can accept the default values and click Finish.
Figure 1-4.
Naming your files
Android Studio will then take a moment to create the general template for your Hello World application. If you look through the source code for this application, you will notice over a dozen files just in Java. You may also notice that some of the files, such as VideoDetailsFragment.java , contain code that is deprecated, or no longer recommended for use by Google. For now, go ahead and ignore them as you will learn about the different recommended components for a media application later in this book.