Handling Features Not Supported on TV

Source: Internet
Author: User

TVs are much different from other Android-powered devices: http://blog.csdn.net/sergeycao

They're not mobile.
Out of habit, people use them for watching media with little or no interaction.
People interact with them from a distance.
Because TVs have a different purpose from other devices, they usually don't have hardware features that other Android-powered devices often have. for this reason, the Android system does not support the following features for a TV device:

Hardware Android feature descriptor
Camera android. hardware. camera
GPS android. hardware. location. gps
Microphone android. hardware. microphone
Near Field Communications (NFC) android. hardware. nfc
Telephony android. hardware. telephony
Touchscreen android. hardware. touchscreen


This lesson shows you how to work around features that are not available on TV:

Providing work arounds for some non-supported features.
Checking for available features at runtime and conditionally activating/deactivating certain code paths based on availability of those features.

Work Around Features Not Supported on TV
Android doesn't support touchscreen interaction for TV devices, most TVs don't have touch screens, and interacting with a TV using a touchscreen is not consistent with the 10 foot environment. for these reasons, users interact with Android-powered TVs using a remote. in consideration of this, ensure that every control in your app can be accessed with the D-pad. refer back to the previous two lessonsOptimizing Layouts for TV and Optimize Navigation for TV for more details on this topic. the Android system assumes that a device has a touchscreen, so if you want your application to run on a TV, you mustexplicitly disable the touchscreen requirement in your manifest file:

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

Although a TV doesn' t have a camera, you can still provide a photography-related application on a TV. for example, if you have an app that takes, views and edits photos, you can disable its picture-taking functionality for TVs and still allow users to view and even edit photos. the next section talks about how to deactivate or activate specific functions in the application based on runtime device type detection.

Because TVs are stationary, indoor devices, they don't have built-in GPS. if your application uses location information, allow users to search for a location or use a "static" location provider to get a location from the zip code configured during the TV setup.

LocationManager locationManager = (LocationManager) this. getSystemService (Context. LOCATION_SERVICE );
Location location = locationManager. getLastKnownLocation ("static ");
Geocoder geocoder = new Geocoder (this );
Address address = null;

Try {
Address = geocoder. getFromLocation (location. getLatitude (), location. getlongdistance (), 1). get (0 );
Log. d ("Zip code", address. getPostalCode ());

} Catch (IOException e ){
Log. e (TAG, "Geocoder error", e );
}

TVs usually don't support microphones, but if you have an application that uses voice control, you can create a mobile device app that takes voice input and then acts as a remote control for a TV.

Check for Available Features at Runtime
To check if a feature is available at runtime, call hasSystemFeature (String ). this method takes a single argument: a string corresponding to the feature you want to check. for example, to check for touchscreen, usehasSystemFeature (String) with the argument FEATURE_TOUCHSCREEN.

The following code snippet demonstrates how to detect device type at runtime based on supported features:

// Check if android. hardware. telephony feature is available.
If (getPackageManager (). hasSystemFeature ("android. hardware. telephony ")){
Log. d ("Mobile Test", "Running on phone ");
// Check if android. hardware. touchscreen feature is available.
} Else if (getPackageManager (). hasSystemFeature ("android. hardware. touchscreen ")){
Log. d ("Tablet Test", "Running on devices that don't support telphony but have a touchscreen .");
} Else {
Log. d ("TV Test", "Running on a TV! ");
}

This is just one example of using runtime checks to deactivate app functionality that depends on features that aren't available on TVs.

 

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.