官网:https://developer.android.com/training/tv/start/hardware.html


电视硬件与其他Android设备明显不同。电视不包括一些其他Android装置,诸如触摸屏,摄像头,以及GPS接收器。为了让用户与电视应用进行互动,他们必须使用一个遥控器或游戏手柄。当你建立了一个电视应用程序,你必须仔细考虑硬件的限制和在电视上运行的硬件要求。


检查电视设备

下面的代码用于检查app是否运行在电视设备上  (在某机顶盒上测试发现,返回的是UI_MODE_TYPE_NORMAL)
public static final String TAG = "DeviceTypeRuntimeCheck";UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {    Log.d(TAG, "Running on a TV Device")} else {    Log.d(TAG, "Running on a non-TV Device")}

处理不支持的硬件特性


电视不支持的硬件特性

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

参考 特性完整表

声明需要的硬件特性

Android应用程序可以声明硬件功能要求在应用程序清单,以确保他们不被安装在不提供这些功能的设备上。
如果你是扩展现有应用程序使用在电视上,仔细检查你的应用程序的清单上的任何硬件要求声明,它们可能会阻止应用被安装在一个电视设备上。


声明权限(硬件特性需要)

一些硬件特性暗示了需要相应的权限
Permission Implied hardware feature
RECORD_AUDIO android.hardware.microphone
CAMERA android.hardware.camera and 
android.hardware.camera.autofocus
ACCESS_COARSE_LOCATION android.hardware.location and 
android.hardware.location.network
ACCESS_FINE_LOCATION android.hardware.location and 
android.hardware.location.gps

检查硬件可用性

例:
// Check if the telephony hardware feature is available.if (getPackageManager().hasSystemFeature("android.hardware.telephony")) {    Log.d("HardwareFeatureTest", "Device can make phone calls");}// Check if android.hardware.touchscreen feature is available.if (getPackageManager().hasSystemFeature("android.hardware.touchscreen")) {    Log.d("HardwareFeatureTest", "Device has a touch screen.");}


关于GPS

电视是静止的,室内设备,没有内置的全球定位系统(GPS)接收器。如果您的应用程序使用位置信息,您仍然可以允许用户搜索一个位置,或使用一个静态位置提供者,如邮政编码在电视设备的配置设置。
// Request a static location from the location managerLocationManager locationManager = (LocationManager) this.getSystemService(        Context.LOCATION_SERVICE);Location location = locationManager.getLastKnownLocation("static");// Attempt to get postal or zip code from the static location objectGeocoder 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);}

配置改变处理

              ...




更多相关文章

  1. Android和IOS系统对比
  2. Android(安卓)学习笔记【基础扫盲篇】
  3. Android应用程序启动过程源代码分析
  4. Android"重力加速度传感器"从驱动到应用层全程分析
  5. Android的权限控制机制
  6. android
  7. Android的权限控制机制
  8. Android(安卓)文件格式
  9. 【Android】Android(安卓)4.0 无法接收开机广播的问题

随机推荐

  1. 2021.6.28
  2. 学习环境搭建及浅谈对Http协议的理解
  3. vscode的下载和安装以及常用插件的部署和
  4. 开学第一课
  5. VS code下载安装插件以及http协议
  6. 0426php第一天
  7. 网站快速排名优化_企业站优化必读
  8. 学习第二天0629
  9. 0628作业
  10. html制作table