Get Started with TV Apps

Previous Next

This lesson teaches you how to

  1. Determine Media Format Support
  2. Setup a TV Project
  3. Add TV Support Libraries
  4. Build TV Apps
  5. Run TV Apps

You should also read

  1. TV Design
  2. Building TV Layouts

TV apps use the same structure as those for phones and tablets. This similarity means you can modify your existing apps to also run on TV devices or create new apps based on what you already know about building apps for Android.

Important:There are specific requirements your app must meet to qualify as an Android TV app on Google Play. For more information, see the requirements listed inTV App Quality.

This lesson describes how to prepare your development environment for building TV apps, and the minimum required changes to enable an app to run on TV devices.

Determine Media Format Support

See the following documentation for information about the codecs, protocols, and formats supported by Android TV.

  • Supported Media Formats
  • DRM
  • android.drm
  • ExoPlayer
  • android.media.MediaPlayer

Set up a TV Project

This section discusses how to modify an existing app to run on TV devices, or create a new one. These are the main components you must use to create an app that runs on TV devices:

  • Activity for TV(Required) - In your application manifest, declare an activity that is intended to run on TV devices.
  • TV Support Libraries(Optional) - There are severalSupport Librariesavailable for TV devices that provide widgets for building user interfaces.

Prerequisites

Before you begin building apps for TV, you must:

  • Update your SDK tools to version 24.0.0 or higher
    The updated SDK tools enable you to build and test apps for TV.
  • Update your SDK with Android 5.0 (API 21) or higher
    The updated platform version provides new APIs for TV apps.
  • Create or update your app project
    In order to access new APIs for TV devices, you must create a project or modify an existing project that targets Android 5.0 (API level 21) or higher.

Declare a TV Activity

An application intended to run on TV devices must declare a launcher activity for TV in its manifest using aCATEGORY_LEANBACK_LAUNCHERintent filter. This filter identifies your app as being enabled for TV, and is required for your app to be considered a TV app in Google Play. Declaring this intent also identifies which activity in your app to launch when a user selects its icon on the TV home screen.

The following code snippet shows how to include this intent filter in your manifest:

<application android:banner="@drawable/banner" > ... <activity  android:name="com.example.android.MainActivity"  android:label="@string/app_name" >  <intent-filter>   <action android:name="android.intent.action.MAIN" />   <category android:name="android.intent.category.LAUNCHER" />  </intent-filter> </activity> <activity  android:name="com.example.android.TvActivity"  android:label="@string/app_name"  android:theme="@style/Theme.Leanback">  <intent-filter>   <action android:name="android.intent.action.MAIN" />   <category android:name="android.intent.category.LEANBACK_LAUNCHER" />  </intent-filter> </activity></application>

The second activity manifest entry in this example specifies that activity as the one to launch on a TV device.

Caution:If you do not include theCATEGORY_LEANBACK_LAUNCHERintent filter in your app, it is not visible to users running the Google Play store on TV devices. Also, if your app does not have this filter when you load it onto a TV device using developer tools, the app does not appear in the TV user interface.

If you are modifying an existing app for use on TV, your app should not use the same activity layout for TV that it does for phones and tablets. The user interface of your TV app (or TV portion of your existing app) should provide a simpler interface that can be easily navigated using a remote control from a couch. For guidelines on designing an app for TV, see theTV Designguide. For more information on the minimum implementation requirements for interface layouts on TV, seeBuilding TV Layouts.

Declare Leanback support

Declare that your app uses the Leanback user interface required by Android TV. If you are developing an app that runs on mobile (phones, wearables, tablets, etc.) as well as Android TV, set therequiredattribute value tofalse. If you set therequiredattribute value totrue, your app will run only on devices that use the Leanback UI.

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

Declare touchscreen not required

Applications that are intended to run on TV devices do not rely on touch screens for input. In order to make this clear, the manifest of your TV app must declare that a theandroid.hardware.touchscreenfeature is not required. This setting identifies your app as being able to work on a TV device, and is required for your app to be considered a TV app in Google Play. The following code example shows how to include this manifest declaration:

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

Caution:You must declare that a touch screen is not required in your app manifest, as shown this example code, or your app cannot appear in the Google Play store on TV devices.

An application must provide a home screen banner for each localization if it includes a Leanback launcher intent filter. The banner is the app launch point that appears on the home screen in the apps and games rows. Desribe the banner in the manifest as follows:

<application  ...  android:banner="@drawable/banner" >  ...</application>

Use theandroid:bannerattribute with the<application>tag to supply a default banner for all application activities, or with the<activity>tag to supply a banner for a specific activity.

SeeBannersin the UI Patterns for TV design guide.

Change the launcher color

When a TV app launches, the system displays an animation that resembles an expanding, filled circle. To customize the color of this animation, set theandroid:colorPrimaryattribute of your TV app or activity to a specific color. You should also set two additional transition overlap attributes totrue, as shown in the following snippet from a theme resource XML file:

<resources>  <style ... >   <item name="android:colorPrimary">@color/primary</item>   <item name="android:windowAllowReturnTransitionOverlap">true</item>   <item name="android:windowAllowEnterTransitionOverlap">true</item>  </style></resources>

For more information about working with themes and styles, seeStyles and Themes.

Add TV Support Libraries

The Android SDK includes support libraries that are intended for use with TV apps. These libraries provide APIs and user interface widgets for use on TV devices. The libraries are located in the<sdk>/extras/android/support/directory. Here is a list of the libraries and their general purpose:

  • v17 leanback library- Provides user interface widgets for TV apps, particularly for apps that do media playback.
  • v7 recyclerview library- Provides classes for managing display of long lists in a memory efficient manner. Several classes in the v17 leanback library depend on the classes in this library.
  • v7 cardview library- Provides user interface widgets for displaying information cards, such as media item pictures and descriptions.

Note:You are not required to use these support libraries for your TV app. However, we strongly recommend using them, particularly for apps that provide a media catalog browsing interface.

If you decide to use the v17 leanback library for your app, you should note that it is dependent on thev4 support library. This means that apps that use the leanback support library should include all of these support libraries:

  • v4 support library
  • v7 recyclerview support library
  • v17 leanback support library

The v17 leanback library contains resources, which require you to take specific steps to include it in app projects. For instructions on importing a support library with resources, seeSupport Library Setup.

Build TV Apps

After you have completed the steps described above, it's time to start building apps for the big screen! Check out these additional topics to help you build your app for TV:

  • Building TV Playback Apps- TVs are built to entertain, so Android provides a set of user interface tools and widgets for building TV apps that play videos and music, and let users browse for the content they want.
  • Helping Users Find Your Content on TV- With all the content choices at users' fingertips, helping them find content they enjoy is almost as important as providing that content. This training discusses how to surface your content on TV devices.
  • Building TV Games- TV devices are a great platform for games. See this topic for information on building great game experiences for TV.
  • Building Live TV Apps- Present your video content in a linear, "broadcast TV" style with channels and programs that your users can access through a program guide as well as the channel up/down buttons.

Run TV Apps

Running your app is an important part of the development process. The AVD Manager in the Android SDK provides the device definitions that allow you to create virtual TV devices for running and testing your applications.

To create an virtual TV device:

  1. Start the AVD Manager. For more information, see theAVD Managerhelp.
  2. In the AVD Manager dialog, click theDevice Definitionstab.
  3. Select one of the Android TV device definitions and clickCreate AVD.
  4. Select the emulator options and clickOKto create the AVD.

    Note:For best performance of the TV emulator device, enable theUse Host GPUoption and, where supported, use virtual device acceleration. For more information on hardware acceleration of the emulator, seeUsing the Emulator.

To test your application on the virtual TV device:

  1. Compile your TV application in your development environment.
  2. Run the application from your development environment and choose the TV virtual device as the target.

For more information about using emulators see,Using the Emulator. For more information on deploying apps from Android Studio to virtual devices, seeDebugging with Android Studio.

总结:******************************************************************************************* 总体和手机端和pad 端的开发是一样的,但是交互的方式是有本质的区别的.






更多相关文章

  1. 阿里、腾讯、百度、网易、美团Android面试经验分享,拿到了百度、
  2. Android的线程详解(几种实现方法及区别)
  3. Android(安卓)各个版本区别及如何选择
  4. [CyanogenMOD移植教程]第二章:android 源码总体结构
  5. Activity intent intent filter 广播接收器的区别
  6. Android中的Thread与AsyncTask的区别
  7. Android中printf和LOGE区别
  8. Android(安卓)Parcelable和Serializable区别
  9. Android内、外存储 易混淆点剖析(/mnt/sdcard、/storage/sdcard0

随机推荐

  1. Android(安卓)6.0运行时权限处理与封装(一
  2. Android中点击空白区域隐藏软键盘功能实
  3. 使用Intel的虚拟化技术(vt-x)加速Android模
  4. Android(安卓)C/JAVA 输出CallStack
  5. 在Android中调用WebService实例
  6. 个人知我见-如何成为一名android开发者?
  7. iOS开发-Objective-C与JavaScript交互
  8. Android(安卓)Service 通知Activity更新
  9. Router—一个高效,使用方便,基于动态代理实
  10. [Unity2d系列教程] 003.Unity如何调用and