184 lines
6.5 KiB
Plaintext
184 lines
6.5 KiB
Plaintext
page.title=Hardware Features on TV
|
|
page.tags="unsupported"
|
|
|
|
@jd:body
|
|
|
|
<div id="qv-wrapper">
|
|
<div id="qv">
|
|
<h2>In this document</h2>
|
|
<ol>
|
|
<li><a href="#unsupported-features">Unsupported Hardware Features</a></li>
|
|
<li><a href="#workaround-features">Handling Unsupported Features</a></li>
|
|
<li><a href="#check-features">Checking Available Features</a>
|
|
<ol>
|
|
<li><a href="#no-touchscreen">Touch screen</a></li>
|
|
<li><a href="#no-camera">Camera</a></li>
|
|
<li><a href="#no-gps">GPS</a></li>
|
|
</ol>
|
|
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
|
|
<p>TVs do not have some of the hardware features found on other Android devices.
|
|
Touch screens, cameras, and GPS receivers are some of the most commonly used hardware features
|
|
which are typically not available on a TV. When you build an app for TV, you must carefully
|
|
consider if your app can handle not having these features and, if necessary, work around them.</p>
|
|
|
|
<p>This guide discusses the hardware features not available on TV devices and shows you how to
|
|
work around those limitations in your app. For more information on filtering and declaring
|
|
features in the manifest, see the
|
|
<a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">uses-feature</a> guide.</p>
|
|
|
|
|
|
<h2 id="unsupported-features">Unsupported Hardware Features</h2>
|
|
|
|
<p>TVs have a different purpose from other devices, and so they do not 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:
|
|
|
|
<table>
|
|
<tr>
|
|
<th>Hardware</th>
|
|
<th>Android feature descriptor</th>
|
|
</tr>
|
|
<tr>
|
|
<td>Camera</td>
|
|
<td>android.hardware.camera</td>
|
|
</tr>
|
|
<tr>
|
|
<td>GPS</td>
|
|
<td>android.hardware.location.gps</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Microphone</td>
|
|
<td>android.hardware.microphone</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Near Field Communications (NFC)</td>
|
|
<td>android.hardware.nfc</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Telephony</td>
|
|
<td>android.hardware.telephony</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Touchscreen</td>
|
|
<td>android.hardware.touchscreen</td>
|
|
</tr>
|
|
</table>
|
|
</p>
|
|
|
|
|
|
<h2 id="check-features">Checking Available Features</h2>
|
|
|
|
<p>To check if a feature is available at runtime, call {@link
|
|
android.content.pm.PackageManager#hasSystemFeature(String)}. This method takes a single string
|
|
argument that specifies the feature you want to check. For example, to check for a touch screen,
|
|
use {@link android.content.pm.PackageManager#hasSystemFeature(String)} with the argument
|
|
{@link android.content.pm.PackageManager#FEATURE_TOUCHSCREEN}.</p>
|
|
|
|
<p>The following code example demonstrates how to detect the availability of a hardware features
|
|
at runtime:</p>
|
|
|
|
<pre>
|
|
// Check if the telephony hardware 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 telephony but "+
|
|
"do have a touch screen.");
|
|
} else {
|
|
Log.d("TV Test", "Running on a TV!");
|
|
}
|
|
</pre>
|
|
|
|
<p class="note">
|
|
<strong>Note:</strong> You can also use the {@link android.app.UiModeManager#getCurrentModeType
|
|
UiModeManager.getCurrentModeType()} method to detect the current platform type. For TV devices,
|
|
this method returns a value of {@link android.content.res.Configuration#UI_MODE_TYPE_TELEVISION
|
|
Configuration.UI_MODE_TYPE_TELEVISION}.
|
|
</p>
|
|
|
|
|
|
<h2 id="workaround-features">Handling Unsupported Features</h2>
|
|
|
|
<p>Depending on the design and functionality of your app, you may be able to work around certain
|
|
hardware features being unavailable. This section discusses how to work around specific hardware
|
|
features.</p>
|
|
|
|
|
|
<h3 id="no-touchscreen">Touch screen</h3>
|
|
|
|
<p>Android doesn't support touch screen interaction for TV devices, since most TVs don't have touch
|
|
screens, and using a touch screen is not consistent with a viewing environment where the user is
|
|
seated 10 feet away from the display.</p>
|
|
|
|
<p>On TV devices, you should work around this limitation by supporting navigation using a directional
|
|
pad (D-pad) on TV remote control. For more information on properly supporting navigation using
|
|
TV-friendly controls, see <a href="{@docRoot}preview/tv/ui/navigation.html">Navigation for
|
|
TV</a>.</p>
|
|
|
|
<p>You can explicitly declare if your application requires (or does not require) a touch screen
|
|
by including the following entry in your manifest:</p>
|
|
|
|
<pre>
|
|
<uses-feature android:name="android.hardware.touchscreen"
|
|
android:required="false"/>
|
|
</pre>
|
|
|
|
|
|
<h3 id="no-camera">Camera</h3>
|
|
|
|
<p>Although a TV typically does not 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. If you decide that you want to enable your camera-related application to work on a
|
|
TV device without a camera, you can add an attribute to your app manifest declaring that
|
|
a camera is not required by your app:</p>
|
|
|
|
<pre>
|
|
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
|
</pre>
|
|
|
|
<p>If you enable your application to run without a camera, you should add code to your application
|
|
that detects if the camera feature is available and makes adjustments to the operation of your app.
|
|
The following code example demonstrates how to detect the presence of a camera:</p>
|
|
|
|
<pre>
|
|
// Check if the camera hardware feature is available.
|
|
if (getPackageManager().hasSystemFeature("android.hardware.camera")) {
|
|
Log.d("Camera test", "Camera available!");
|
|
} else {
|
|
Log.d("Camera test", "No camera available. View and edit features only.");
|
|
}
|
|
</pre>
|
|
|
|
|
|
<h3 id="no-gps">GPS</h3>
|
|
|
|
<p>TVs are stationary, indoor devices, and do not have built-in global positioning system (GPS)
|
|
receivers. If your application uses location information, you can still allow users to search
|
|
for a location, or use a static location provider such as a zip code configured during the
|
|
TV device setup.</p>
|
|
|
|
<pre>
|
|
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.getLongitude(), 1).get(0);
|
|
Log.d("Zip code", address.getPostalCode());
|
|
|
|
} catch (IOException e) {
|
|
Log.e(TAG, "Geocoder error", e);
|
|
}
|
|
</pre>
|
|
|