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