blob: 2766e90a39a595d8f5a6e5320fbf73b7ac1886ef [file] [log] [blame]
Joe Fernandezd86a2f52014-09-11 09:52:07 -07001page.title=Get Started with TV Apps
Scott Rowe7515d182014-12-09 15:51:39 -08002page.tags="leanback","recyclerview","launcher"
Joe Fernandezd86a2f52014-09-11 09:52:07 -07003
4trainingnavtop=true
5startpage=true
6
7@jd:body
8
9<div id="tb-wrapper">
10<div id="tb">
11 <h2>This lesson teaches you how to</h2>
12 <ol>
13 <li><a href="#dev-project">Setup a TV Project</a></li>
Joe Fernandez9fe42212014-11-04 22:31:55 -080014 <li><a href="#tv-libraries">Add TV Support Libraries</a></li>
Joe Fernandezd86a2f52014-09-11 09:52:07 -070015 <li><a href="#build-it">Build TV Apps</a></li>
16 <li><a href="#run">Run TV Apps</a></li>
17 </ol>
18 <h2>You should also read</h2>
19 <ol>
20 <li><a href="{@docRoot}design/tv/index.html">
21 TV Design</a></li>
22 <li><a href="{@docRoot}training/tv/start/layouts.html">
23 Building TV Layouts</a></li>
24 </ol>
25</div>
26</div>
27
28<p>
29 TV apps use the same structure as those for phones and tablets. This similarity means you can
30 modify your existing apps to also run on TV devices or create new apps based on what you already
31 know about building apps for Android.
32</p>
33
34<p class="note">
Joe Fernandezcd2445a2014-10-07 22:55:44 -070035 <strong>Important:</strong> There are specific requirements your app must meet to
Joe Fernandezd86a2f52014-09-11 09:52:07 -070036 qualify as an Android TV app on Google Play. For more information, see the requirements listed
37 in <a href="{@docRoot}distribute/essentials/quality/tv.html">TV App Quality</a>.
38</p>
39
40<p>
41 This lesson describes how to prepare your development environment for building TV apps, and the
42 minimum required changes to enable an app to run on TV devices.
43</p>
44
45
46<h2 id="dev-project">Set up a TV Project</h2>
47
48<p>
49 This section discusses how to modify an existing app to run on TV devices, or create a new one.
50 These are the main components you must use to create an app that runs on TV devices:
51</p>
52
53<ul>
54 <li><strong>Activity for TV</strong> (Required) - In your application manifest,
55 declare an activity that is intended to run on TV devices.</li>
56 <li><strong>TV Support Libraries</strong> (Optional) - There are several
57 <a href="#tv-libraries">Support Libraries</a>
58 available for TV devices that provide widgets for building user interfaces.</li>
59</ul>
60
61
62<h3 id="prerequisites">Prerequisites</h3>
63
64<p>Before you begin building apps for TV, you must:</p>
65
66<ul>
67 <li><strong><a href="{@docRoot}sdk/installing/adding-packages.html#GetTools">
68 Update your SDK tools to version 24.0.0 or higher</a></strong>
69 <br>
70 The updated SDK tools enable you to build and test apps for TV.
71 </li>
72 <li><strong><a href="{@docRoot}sdk/installing/adding-packages.html#GetTools">
73 Update your SDK with Android 5.0 (API 21) or higher</a></strong>
74 <br>
75 The updated platform version provides new APIs for TV apps.
76 </li>
77 <li><strong><a href="{@docRoot}sdk/installing/create-project.html">
78 Create or update your app project</a></strong>
79 <br>
80 In order to access new APIs for TV devices, you must create a project or modify an existing
81 project that targets Android 5.0 (API level 21) or higher.
82 </li>
83</ul>
84
85
86<h3 id="tv-activity">Declare a TV Activity</h3>
87
88<p>An application intended to run on TV devices must declare a launcher activity for TV
89 in its manifest using a {@link android.content.Intent#CATEGORY_LEANBACK_LAUNCHER} intent filter.
Joe Fernandez9fe42212014-11-04 22:31:55 -080090 This filter identifies your app as being enabled for TV, and is required for your app to be
91 considered a TV app in Google Play. Declaring this intent also identifies which activity
Joe Fernandezd86a2f52014-09-11 09:52:07 -070092 in your app to launch when a user selects its icon on the TV home screen.</p>
93
Joe Fernandezd86a2f52014-09-11 09:52:07 -070094<p>The following code snippet shows how to include this intent filter in your manifest:</p>
95
96<pre>
Scott Rowe4c3a07b2014-10-29 13:32:30 -070097&lt;application
98 android:banner="&#64;drawable/banner" &gt;
Joe Fernandezd86a2f52014-09-11 09:52:07 -070099 ...
100 &lt;activity
101 android:name=&quot;com.example.android.MainActivity&quot;
102 android:label=&quot;@string/app_name&quot; &gt;
103
104 &lt;intent-filter&gt;
105 &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
106 &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
107 &lt;/intent-filter&gt;
108 &lt;/activity&gt;
109
110 &lt;activity
111 android:name=&quot;com.example.android.<strong>TvActivity</strong>&quot;
112 android:label=&quot;&#64;string/app_name&quot;
113 android:theme=&quot;&#64;style/Theme.Leanback&quot;&gt;
114
115 &lt;intent-filter&gt;
116 &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
117 &lt;category android:name="<strong>android.intent.category.LEANBACK_LAUNCHER</strong>" /&gt;
118 &lt;/intent-filter&gt;
119
120 &lt;/activity&gt;
121&lt;/application&gt;
122</pre>
123
124<p>
125 The second activity manifest entry in this example specifies that activity as the one to
126 launch on a TV device.
127</p>
128
Joe Fernandez9fe42212014-11-04 22:31:55 -0800129<p class="caution">
130 <strong>Caution:</strong> If you do not include the
131 {@link android.content.Intent#CATEGORY_LEANBACK_LAUNCHER} intent filter in
132 your app, it is not visible to users running the Google Play store on TV devices. Also, if your
133 app does not have this filter when you load it onto a TV device using developer tools, the app
134 does not appear in the TV user interface.
135</p>
136
Joe Fernandezd86a2f52014-09-11 09:52:07 -0700137<p>
138 If you are modifying an existing app for use on TV, your app should not use the same
139 activity layout for TV that it does for phones and tablets. The user interface of your TV app (or
140 TV portion of your existing app) should provide a simpler interface that can be easily navigated
141 using a remote control from a couch. For guidelines on designing an app for TV, see the <a href=
142 "{@docRoot}design/tv/index.html">TV Design</a> guide. For more information on the minimum
143 implementation requirements for interface layouts on TV, see <a href=
144 "{@docRoot}training/tv/start/layouts.html">Building TV Layouts</a>.
145</p>
146
Scott Rowe7515d182014-12-09 15:51:39 -0800147<h3 id="leanback-req">Declare Leanback support</h3>
148
149<p>
150 Declare that your app uses the Leanback user interface required by Android TV. If you are developing
151 an app that runs on mobile (phones, wearables, tablets, etc.) as well as Android TV, set the
152 {@code required} attribute value to {@code false}. If you set the {@code required} attribute value
153 to {@code true}, your app will run only on devices that use the Leanback UI.
154</p>
155
156<pre>
157&lt;manifest&gt;
158 &lt;uses-feature android:name="android.software.leanback"
159 android:required="false" /&gt;
160 ...
161&lt;/manifest&gt;
162</pre>
Joe Fernandez9fe42212014-11-04 22:31:55 -0800163
164<h3 id="no-touchscreen">Declare touchscreen not required</h3>
165
166<p>
167 Applications that are intended to run on TV devices do not rely on touch screens for input. In
168 order to make this clear, the manifest of your TV app must declare that a the {@code
169 android.hardware.touchscreen} feature is not required. This setting identifies your app as being
170 able to work on a TV device, and is required for your app to be considered a TV app in Google
171 Play. The following code example shows how to include this manifest declaration:
172</p>
173
174<pre>
175&lt;manifest&gt;
Scott Rowe7515d182014-12-09 15:51:39 -0800176 &lt;uses-feature android:name="android.hardware.touchscreen"
177 android:required="false" /&gt;
Joe Fernandez9fe42212014-11-04 22:31:55 -0800178 ...
179&lt;/manifest&gt;
180</pre>
181
182<p class="caution">
183 <strong>Caution:</strong> You must declare that a touch screen is not required in your app
184 manifest, as shown this example code, or your app cannot appear in the Google Play store on TV
185 devices.
186</p>
187
Scott Rowe4c3a07b2014-10-29 13:32:30 -0700188<h3 id="banner">Provide a home screen banner</h3>
189
190<p>
Scott Rowe7515d182014-12-09 15:51:39 -0800191 An application must provide a home screen banner for each localization if it includes a Leanback
192 launcher intent filter. The banner is the app launch point that appears on the home screen in the
193 apps and games rows. Desribe the banner in the manifest as follows:
Scott Rowe4c3a07b2014-10-29 13:32:30 -0700194</p>
195
196<pre>
197&lt;application
Joe Fernandez9fe42212014-11-04 22:31:55 -0800198 ...
Scott Rowe4c3a07b2014-10-29 13:32:30 -0700199 android:banner="&#64;drawable/banner" &gt;
Joe Fernandez9fe42212014-11-04 22:31:55 -0800200
201 ...
Scott Rowe4c3a07b2014-10-29 13:32:30 -0700202&lt;/application&gt;
203</pre>
204
205<p>
206 Use the <a href="{@docRoot}guide/topics/manifest/application-element.html#banner">{@code android:banner}</a>
207 attribute with the <a href="{@docRoot}guide/topics/manifest/application.html"><code>&lt;application&gt;</code></a>
208 tag to supply a default banner for all application activities, or with the
209 <a href="{@docRoot}guide/topics/manifest/activity-element.html"><code>&lt;activity&gt;</code></a>
210 tag to supply a banner for a specific activity.
211</p>
212
213<p>
214 See <a href="{@docRoot}design/tv/patterns.html#banner">Banners</a> in the UI Patterns for TV
215 design guide.
216</p>
Joe Fernandezd86a2f52014-09-11 09:52:07 -0700217
Joe Fernandez9fe42212014-11-04 22:31:55 -0800218<h2 id="tv-libraries">Add TV Support Libraries</h3>
Joe Fernandezd86a2f52014-09-11 09:52:07 -0700219
220<p>
221 The Android SDK includes support libraries that are intended for use with TV apps. These
222 libraries provide APIs and user interface widgets for use on TV devices. The libraries are
223 located in the {@code &lt;sdk&gt;/extras/android/support/} directory. Here is a list of the
224 libraries and their general purpose:
225</p>
226
227<ul>
228 <li><a href="{@docRoot}tools/support-library/features.html#v17-leanback">
229 <strong>v17 leanback library</strong></a> - Provides user interface widgets for TV apps,
230 particularly for apps that do media playback.
231 </li>
232 <li><a href="{@docRoot}tools/support-library/features.html#v7-recyclerview">
233 <strong>v7 recyclerview library</strong></a> - Provides classes for managing display of long
234 lists in a memory efficient manner. Several classes in the v17 leanback library depend on the
235 classes in this library.
236 </li>
237 <li><a href="{@docRoot}tools/support-library/features.html#v7-cardview">
238 <strong>v7 cardview library</strong></a> - Provides user interface widgets for displaying
239 information cards, such as media item pictures and descriptions.
240 </li>
241</ul>
242
243<p class="note">
244 <strong>Note:</strong> You are not required to use these support libraries for your TV app.
245 However, we strongly recommend using them, particularly for apps that provide a media catalog
246 browsing interface.
247</p>
248
249<p>
250 If you decide to use the v17 leanback library for your app, you should note that it is dependent
251 on the <a href="{@docRoot}tools/support-library/features.html#v4">v4 support library</a>. This
252 means that apps that use the leanback support library should include all of these support
253 libraries:
254</p>
255
256<ul>
257 <li>v4 support library</li>
258 <li>v7 recyclerview support library</li>
259 <li>v17 leanback support library</li>
260</ul>
261
262<p>
263 The v17 leanback library contains resources, which require you to take specific steps to include
264 it in app projects. For instructions on importing a support library with resources, see
265 <a href="{@docRoot}tools/support-library/setup.html#libs-with-res">Support Library Setup</a>.
266</p>
267
268
269<h2 id="build-it">Build TV Apps</h2>
270
271<p>After you have completed the steps described above, it's time to start building apps for
272 the big screen! Check out these additional topics to help you build your app for TV:
273
274<ul>
275 <li>
276 <a href="{@docRoot}training/tv/playback/index.html">Building TV Playback Apps</a> - TVs are
277 built to entertain, so Android provides a set of user interface tools and widgets for building
278 TV apps that play videos and music, and let users browse for the content they want.
279 </li>
280 <li>
Scott Rowe7515d182014-12-09 15:51:39 -0800281 <a href="{@docRoot}training/tv/discovery/index.html">Helping Users Find Your Content on TV</a> -
282 With all the content choices at users' fingertips, helping them find content they enjoy is almost
283 as important as providing that content. This training discusses how to surface your content on
284 TV devices.
Joe Fernandezd86a2f52014-09-11 09:52:07 -0700285 </li>
286 <li>
287 <a href="{@docRoot}training/tv/games/index.html">Games for TV</a> - TV devices are a great
288 platform for games. See this topic for information on building great game experiences for TV.
289 </li>
290</ul>
291
292
293<h2 id="run">Run TV Apps</h2>
294
295<p>
296 Running your app is an important part of the development process. The AVD Manager in the Android
297 SDK provides the device definitions that allow you to create virtual TV devices for running and
298 testing your applications.
299</p>
300
301<p>To create an virtual TV device:</p>
302
303<ol>
304 <li>Start the AVD Manager. For more information, see the
305 <a href="{@docRoot}tools/help/avd-manager.html">AVD Manager</a> help.</li>
306 <li>In the AVD Manager dialog, click the <strong>Device Definitions</strong> tab.</li>
307 <li>Select one of the Android TV device definitions and click <strong>Create AVD</strong>.</li>
308 <li>Select the emulator options and click <strong>OK</strong> to create the AVD.
309 <p class="note">
310 <strong>Note:</strong> For best performance of the TV emulator device, enable the <strong>Use
311 Host GPU</strong> option and, where supported, use virtual device acceleration. For
312 more information on hardware acceleration of the emulator, see
313 <a href="{@docRoot}tools/devices/emulator.html#acceleration">Using the Emulator</a>.
314 </p>
315 </li>
316</ol>
317
318<p>To test your application on the virtual TV device:</p>
319
320<ol>
321 <li>Compile your TV application in your development environment.</li>
322 <li>Run the application from your development environment and choose the TV virtual device as
323 the target.</li>
324</ol>
325
326<p>
327 For more information about using emulators see, <a href="{@docRoot}tools/devices/emulator.html">
328 Using the Emulator</a>. For more information on deploying apps from Android Studio to virtual
329 devices, see <a href="{@docRoot}sdk/installing/studio-debug.html">Debugging with Android
330 Studio</a>. For more information about deploying apps to emulators from Eclipse with ADT, see
331 <a href="{@docRoot}tools/building/building-eclipse.html">Building and Running from Eclipse with
332 ADT</a>.
333</p>