Android TV Development Summary (a) What to know before building a TV app

Source: Internet
Author: User

Reprint please the head source link and the tail two-dimensional code together reprint, this article from countercurrent fish yuiop:http://blog.csdn.net/hejjunlin/article/details/52792562

In recent years, the development of smart TV in full swing, Googel also vigorously promote the development of TV and wear equipment, in the Internet, the tuyere is the pig will fly, this sentence is not unreasonable. Traditional TV manufacturers, the basic transformation is committed to the related business of Smart TV.

    • Working with TV hardware
    • Check your TV device on the app
    • Handling Unsupported Hardware Features
    • Declaring hardware requirements for TV
    • Declaring permissions means that the hardware must have this attribute
    • Check Hardware Features
    • Processing controller Disconnect Scene
Working with TV hardware

TV hardware is vastly different from other Android devices. TV does not include some of the hardware features found on other Android devices, such as touch screen, webcam, GPS receiver. Television also relies entirely on ancillary hardware devices. In order for users to interact with the TV application, they must use a remote control or gamepad. When you build an application for your TV, you must carefully consider the limitations and requirements of hardware to operate the TV hardware.

Check your TV device on the app

If you are building an app that runs on TV and other devices, you may need to check what device your app is running on and what kind of action you might be doing in your app.
For example, if you have an app that is intent launched, your app should be checked for device properties to determine if it can activate activity on the TV or on the phone.

Recommend a way to determine if your app is running under a TV device,
Check that the device is running in TV mode by using the Uimodemanager.getcurrentmodetype () method.
The following sample code shows how to check if your application is running on a TV device:

Handling Unsupported Hardware Features

Depending on the design and functionality of your application, you can resolve certain hardware features that are not available. Learn what hardware features are typically not used for TVs, how to detect missing hardware features, and suggest using these features.

    • Unsupported TV Hardware Features

TVS have different effects than other devices, so they don't have some of the hardware features that other Android devices typically have. For this reason, the Android system does not support TV devices with the following features:

Hardware Android Feature Descriptor
Touchscreen Android.hardware.touchscreen
Touchscreen emulator Android.hardware.faketouch
Telephony Android.hardware.telephony
Camera Android.hardware.camera
Near Field Communications (NFC) Android.hardware.nfc
Gps Android.hardware.location.gps
microphone [1] Android.hardware.microphone
Sensors Android.hardware.sensor
Screen in portrait orientation Android.hardware.screen.portrait

Some TV controllers have a microphone, a microphone that is not the same as the hardware feature description. The controller microphone is fully supported.

Declaring hardware requirements for TV

Android apps can declare the hardware features required to be manifest in the app to make sure they are not installed under this app and the device does not provide these features. If you are extending an existing application to use on a TV, double check your application's manifest, because any hardware requirements statement may prevent it from being installed on a TV device.

If your application uses hardware features such as a touchscreen or camera, it is not available on TV, but you can modify the manifest of your application without using these features, indicating that these features are not required by the application. The following manifest code snippet demonstrates how to declare an application that does not require hardware features that are not available on a TV device, even if no applications on the TV device can use these features:

Some features like Android.hardware.camera Subfeatures.front, when feature booting, make sure that the identity required= "false" in any child features, as may be used in the app

All apps are used on TV, the app must declare the touchscreen features described in no need of use. If your application typically uses one or more of the attributes listed above in your manifest file, change these features like android:required attribute setting to False,
Warning: Declaring a hardware feature can be done by setting some property value to True to prevent your app from being installed on a TV device or appearing on the Launcher startup page of an Android TV

Once you have decided to make your hardware features optional applications, you must check the availability of these features at run time and then adjust the behavior of your application.

Declaring permissions means that the hardware must have this attribute

Some uses-permission manifest declarations imply hardware features. This behavior means that requesting some application permission lists can include your app to install and use from your TV device. The following general requirements for permissions create implicit hardware feature requirements:

Permission implied hardware feature
Record_audio Android.hardware.microphone
CAMERA Android.hardware.camera and Android.hardware.camera.autofocus
Access_coarse_location Android.hardware.location
Android.hardware.location.network (Target API level, or lower only.)
Access_fine_location Android.hardware.location
Android.hardware.location.gps (Target API level, or lower only.)

The complete license list request, which means the hardware features required, is seen in the Uses-feature guide. If your application requests one of the attributes listed above, the Uses-feature declaration contains hardware features implied in your manifest, indicating that it is not required (android:required= "false").

Note: If your target app runs Android 5.0 (API level 21) or later, and you use Access_coarse_location or access_fine_location permissions, users can still install your app TV device, Even if the TV device does not have a network card or GPS receiver.

Check Hardware Features

The Android framework can tell you if there are no hardware features available on the device, the application is running. Use the Hassystemfeature (String) method to check for specific functionality at run time. The method takes a string parameter that specifies the function check you want.
The following code example demonstrates how to detect the availability of hardware features at run time:

Touch screen

Android does not support touch screen interactive TV devices because most TVs do not have a touchscreen. Also, using a touchscreen that does not conform to the viewing environment, the user sits 10 feet away from the display. Make sure that your UI elements and text do not need or imply the use of the touchscreen.
On TV devices, you should design your application using this interactive model by supporting navigation with a directional lever (arrow key) in a TV remote control.

Camera

Although the TV usually does not have a camera, you can still provide a photography-related TV application. For example, if you have an application that needs to view and edit photos, you can disable it's take pictures feature TV even allows users to view and edit photos. If you decide to let the Camera-related app work on the TV, add the following feature declaration application manifest:

If you do not have a webcam, make the app run code add to your application, detect if camera features are available, and make adjustments to the application's operations. The following code example demonstrates how to detect the presence of a camera:

Gps

TVs are stationary, indoor devices, and do not have a built-in Global Positioning System (GPS) receiver. If your application uses location information, you can still allow users to search for a location, or use a static location provider such as postal code in the configuration settings of a TV device.

Handling Controllers

A TV device requires a secondary hardware device to interact with the application, a basic form of a remote controller or game controller. This means that your application must support the direction key input. This also means that your app needs to be in the controller's offline and external devices (such as keyboard) input, not a type of controller (normal remote).

Minimum direction key control

The default controller for a TV device is a directional key. In general, applications should be operable only from a remote controller, under, left, right, select, and Home keys. If your app is a game that usually needs to be controlled with additional game controllers, the app should try to get the game to control with these arrow keys. In this case, the application should also alert the user to the need for a controller and allow them to gracefully exit your game using the arrow key controller.

Processing controller Disconnect Scene

The controller on the TV may be disconnected, such as a Bluetooth device that may have a periodic sleep mode or disconnect from the TV device for power saving. This means that the application may be interrupted or restarted if it is not configured to handle these connection events. These events can occur in one of the following situations:

    • When watching a video for a few minutes long, the arrow keys or game controllers go into sleep mode, disconnect from the TV device, and then reconnect.
    • When in the game, a new player joins the game using a game controller that is not currently connected.
    • When in the game, the player leaves the game and disconnects the game controller.

The activity in any TV app is conditional on disconnecting and reconnecting events and must be configured to handle reconnection events in the app Mainfest file, the following code example demonstrates how to enable an activity to handle configuration changes, including keyboard or navigation device connections, disconnects, or reconnect:

The first time to get blog update reminders, as well as more Android dry, source code Analysis , Welcome to follow my public number, sweep the bottom QR code or long press to identify two-dimensional code, you can pay attention to.




If you feel good, easy to praise, but also to the author's affirmation, can also share this public number to you more people, original not easy

Android TV Development Summary (a) What to know before building a TV app

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.