Handling Unsupported Hardware Features
Posted By : Shifali Rai | 05-Apr-2019
Android TV varies a lot in hardware features when compared to other Android-powered devices. They are not mobile, people interact less with the device and that to from a distance. They are often used for playing media.
This blog helps in understanding the limited hardware features of Android TV and how to work with these limitations. Below is the list of hardware which is not supported by TV:
Features not Supported on Tv
Android devices have a property of defining the hardware feature inside manifest to avoid getting installed on devices that doesn’t support those features. So as there are many features not supported on TV, clearly observe manifest of the app to prevent interruption in installing apps on TV.
If you want to modify your app to support Android TV, then declare features, which are not necessary to your app and is not supported on Android TV as not required inside apps manifest.
Get help with the below code in disabling the unsupported hardware features:
print 'hello world!'<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.software.leanback"
android:required="false" />
<uses-feature
android:name="android.hardware.type.television"
android:required="true"/>
<uses-feature
android:name="android.software.leanback_only"
android:required="false"/>
Caution: Features that are not supported on TV if set to true prevents apps installation and also prevents it to appear on the launcher screen.
After declaring these feature optional to your app, check available feature on runtime and perform action accordingly.
Check Hardware Feature
For checking hardware feature at runtime call method, hasSystemFeature(String). The argument String here takes values corresponding to the feature you want to check.
Add this code to check the hardware feature availability:
// 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("Touchscreen Test", " touchscreen not available");
} else {
Log.d("TV Test", "Running on a TV!");
}
Work with features not Supported on TV
Camera
TV does not have a camera but still, it can support photo-related apps. You can disable only the picture taking the functionality of the camera and can allow editing and viewing functions. Declare the following code inside your manifest:
<uses-feature android:name="android.hardware.camera" android:required="false" />
Now check for the presence of the camera with the help of the following code:
if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.d("Camera test", "Camera available!");
} else {
Log.d("Camera test", "No camera available. View and edit features only.");
}
GPS
Although TV devices are immobile, and there is no feature of built-in GPS, still you can provide its current static location.
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);
}
Microphone
If your app uses a microphone, you can add the functionality of taking voice input which acts as a remote control for the app.
Checking the presence of microphone feature:
if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE)) {
Log.d("MICROPHONE TEST", "microphone available!");
} else {
Log.d("MICROPHONE TEST", "No microphone available. Take voice input.");
}
Conclusion
TV devices and not less than any other Android-powered device, all you have to do are considered its hardware limitation and typical navigation.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Shifali Rai
Android developer: Worked on Android mobile, Android Tv and Fire Tv