Android TV-Building TV Apps,Get Started with TV Apps

desaco發表於2016-01-16

 Note: For details on how to publish your TV apps in Google Play, see Distribute to Android TV.

 Android offers a rich user experience that's optimized for apps running on large screen devices, such as high-definition televisions. Apps on TV offer new opportunities to delight your users from the comfort of their couch.

 TV apps use the same structure as those for phones and tablets. This approach means you can create new TV apps based on what you already know about building apps for Android, or extend your existing apps to also run on TV devices. However, the user interaction model for TV is substantially different from phone and tablet devices. In order to make your app successful on TV devices, you must design new layouts that can be easily understood from 10 feet away, and provide navigation that works with just a directional pad and a select button.

 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.

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

》 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 several Support Libraries available for TV devices that provide widgets for building user interfaces.

》Before you begin building apps for TV, you must:

An application intended to run on TV devices must declare a launcher activity for TV in its manifest using aCATEGORY_LEANBACK_LAUNCHER intent 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.

<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>
 Caution: If you do not include the CATEGORY_LEANBACK_LAUNCHER intent 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.

 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 the required attribute value tofalse. If you set the required attribute value to true, your app will run only on devices that use the Leanback UI.

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

    ...
</application>

Use the android:banner attribute 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.

If you decide to use the v17 leanback library for your app, you should note that it is dependent on the v4 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
》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.

相關文章