Introduction and creation of Android TV APPs

Source: Internet
Author: User
Tags home screen

Recently began to contact Andorid TV programming, found that the current convenient information and comparison is relatively small, but now with the product and user upgrade, involving Android TV and Android watch programming closer to us, this blog began, The process of recording my Android TV from Zero to one is recorded in a note-taking manner.

This blog creation step mainly refers to the official Android documentation .
Get Started with TV Apps

The TV app uses the same structure as the phone and tablet. This similarity means that you can also modify an existing application to run on a TV device or create a new application based on the Android technology that you now have mastered.

1. Create Android TV Project

This blog focuses on how to prepare your development environment for developing TV applications, and minimum requirements for changes that enable an application to run on TV devices.

First, we need to use the following two important components:

activity for TV (required) -in the application's manifest file, we need to declare an activity that needs to be run on the TV side

TV support Libraries (optional) -there are several related supporting packages that provide interactive controls related to TV devices.

Development environment

The above is the most popular web content:

    • SDK tools versions at 24.0.0 and above
    • Android 5.0 (API) SDK and more
    • Create or update your project-to be able to access APIs designed for TV devices, we need to create or modify an existing Project Target SDK version at Andorid 5.0 and above.
Statement a TV Activity (Set up a TV Project)

Activity that runs on the TV device needs to declare the Category_leanback_launcher Intent Filter statement, which ensures that Google Play can identify our app as a TV version, and When we select our app icon on TV, we go to the CATEGORY_LEANBACK_LAUNCHER same activity as the Android phone that we declared.

The following code, Tvactivity will be shown on the TV side, and Mainactivity will be displayed on the phone or tablet side.

<applicationandroid:banner="@drawable/banner" >  ...<activityandroid: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>  <activityandroid: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>
Note: If our app does not contain Category_leanback_launcherActivity that is intended to be filtered, the Google Play store on the TV does not show our app, and our app icon does not appear on the TV desktop when we use the development tool to debug on the TV side or AVD. If you are modifying an existing application to use on TV, your application should not use the same activity layout TV, it only applies to phones and tablets. The user interface of the TV application (or T-V part of an existing application) should provide a simpler interface that can be easily navigated from the couch using and remote control. 1,3 Statement Leanback support

If your app is running on phones, tablets, and TV devices at the same time, you need to set the required property to False, and if set to true, the app can only run on devices that use the Leanback UI.

The following code example shows how to include this manifest declaration:

<manifest>    <uses-feature android:name="android.software.leanback"        android:required="false" />    ...</manifest>
1,4 Statement non-touchscreen (Declare touchscreen not required)

Applications running on TV are not dependent on the touchscreen input or can be understood to not support touch screens. To make this clear, we need to declare android.hardware.touchscreen.

The following code example shows how to include this manifest declaration:

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

Tips:
The above code must also be declared to prove that the touchscreen feature is not required. And in order for Google Play to identify the app as a TV app, it allows apps to work on TV devices.

1,5 provides a homescreen icon (provide a home screen banner)
<application    ...    android:banner="@drawable/banner" >    ...</application>

It needs to be emphasized that his priority is greater than android:icon= "@mipmap/ic_launcher"

1,6 Modifying the load map color (change the launcher color)

When we load an app, we'll show a circular icon loading animation, and we can customize its color.
Set a specific color through android:colorprimary , and also set two additional properties to True, the code is as follows:

<resources>    <style ... >      <itemname="android:colorPrimary">@color/primary</item>      <itemname="android:windowAllowReturnTransitionOverlap">true</item>      <itemname="android:windowAllowEnterTransitionOverlap">true</item>    </style></resources>
2 Add TV Support library (add TV Libraries)

The Android SDK includes a few support libraries for TV apps that contain UI controls for TV apps, which are located in the <sdk>/extras/android/support/ directory. The following is a description of these libraries:

    • V17 Leanback Library-provides some specific controls for media playback.
    • The V7 Recyclerview library-provides a more memory-efficient way to manage the list presentation classes. Meanwhile V17 Leanback
      Some classes in the library also depend on it.
    • The V7 CardView library-contains controls for displaying information cards.

Note: You do not need to use these support libraries in your TV application. However, we strongly recommend that you use them, especially for developing media-related apps.

If you decide to use the V17 Leanback library, it should be noted that it relies on the V4 support Library, which means we end up with the following libraries:

    • V4 Support Library
    • V7 Recyclerview Support Library
    • V17 Leanback Support Library
3. Create TV Apps tutorial (build TV apps)

The above is the official referral link

For entertainment
Help users find content on TV
Create a video game
Create a live app

4, run TV Apps 4.1 Create TV Simulator

1. Start the AVD management and create the virtual machine. and click Create VM

2. Select Category TV, select an Android TV, then click "Next"

Until the following screen appears, click "Finish" to complete the simulator creation process, if the SDK version is too low, you will be prompted to download.

Debugging in the simulator

If your TV apps are error-free, you'll see the following in the simulator.

Through the keyboard operation, in reality by remote control operation. Access to the apps interface appears as follows:

See the above interface, indicating that you have successfully created an Android TV project, you can install to the TV to try!

Finally, a brief explanation of how to operate in the simulator

In order to simulate the operation of TV remote control, we need to be controlled by the keyboard, the keyboard in the upper, lower, left, right, you can move the focus, click the "Enter" key to enter, click the "ESC" key to exit.

Personal GitHub Links

Introduction and creation of Android TV APPs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.