当前位置: 首页 > news >正文

nullnullHandling Features Not Supported on TV 在电视上处理不支持的功能

之前个人几篇文章介绍了改nullnull的文章. 关联文章的地址

    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:

    

HardwareAndroid feature descriptor
Cameraandroid.hardware.camera
GPSandroid.hardware.location.gps
Microphoneandroid.hardware.microphone
Near Field Communications (NFC)android.hardware.nfc
Telephonyandroid.hardware.telephony
Touchscreenandroid.hardware.touchscreen

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

    

  • 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.getLongitude(), 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. 

文章结束给大家分享下程序员的一些笑话语录: 打赌
飞机上,一位工程师和一位程序员坐在一起。程序员问工程师是否乐意和他一起玩一种有趣的游戏。工程师想睡觉,于是他很有礼貌地拒绝了,转身要睡觉。程序员坚持要玩并解释说这是一个非常有趣的游戏:"我问你一个问题,如果你不知道答案,我付你5美元。然后你问我一个问题,如果我答不上来,我付你5美元。"然而,工程师又很有礼貌地拒绝了,又要去睡觉。  程序员这时有些着急了,他说:"好吧,如果你不知道答案,你付5美元;如果我不知道答案,我付50美元。"果然,这的确起了作用,工程师答应了。程序员就问:"从地球到月球有多远?"工程师一句话也没有说,给了程序员5美元。  现在轮到工程师了,他问程序员:"什么上山时有三条腿,下山却有四条腿?"程序员很吃惊地看着工程师,拿出他的便携式电脑,查找里面的资料,过了半个小时,他叫醒工程师并给了工程师50美元。工程师很礼貌地接过钱又要去睡觉。程序员有些恼怒,问:"那么答案是什么呢?"工程师什么也没有说,掏出钱包,拿出5美元给程序员,转身就去睡觉了。

相关文章:

  • 我的vim高亮设置
  • 如何配置oracle数据库的连接
  • Java EE企业系统性能问题的原因和解决建议
  • 使用sqlplus创建表空间
  • 数据库并发操作
  • 列出目录下所有文件
  • Java 程序编译运行
  • Go语言并发之美
  • 我的PGA我作主----搞清楚什么是真正的PGA
  • PostgreSQL在何处处理 sql查询之十一
  • heartbeat 3.0集群(1)集群原理
  • 【乡巴佬】在Word中合理排列文本框与文本
  • c#类的初始化顺序
  • VIM使用系列:位置跳转和块模式
  • js字符串
  • 【MySQL经典案例分析】 Waiting for table metadata lock
  • 08.Android之View事件问题
  • Android Studio:GIT提交项目到远程仓库
  • avalon2.2的VM生成过程
  • Date型的使用
  • exif信息对照
  • JavaWeb(学习笔记二)
  • Laravel Telescope:优雅的应用调试工具
  • MD5加密原理解析及OC版原理实现
  • MySQL数据库运维之数据恢复
  • orm2 中文文档 3.1 模型属性
  • Python爬虫--- 1.3 BS4库的解析器
  • Webpack入门之遇到的那些坑,系列示例Demo
  • 编写高质量JavaScript代码之并发
  • 读懂package.json -- 依赖管理
  • 浮动相关
  • 高度不固定时垂直居中
  • 类orAPI - 收藏集 - 掘金
  • 想晋级高级工程师只知道表面是不够的!Git内部原理介绍
  • 学习使用ExpressJS 4.0中的新Router
  • Spring Batch JSON 支持
  • ​ssh-keyscan命令--Linux命令应用大词典729个命令解读
  • #pragma once
  • (第61天)多租户架构(CDB/PDB)
  • (附源码)计算机毕业设计SSM教师教学质量评价系统
  • (南京观海微电子)——COF介绍
  • (亲测)设​置​m​y​e​c​l​i​p​s​e​打​开​默​认​工​作​空​间...
  • (三)终结任务
  • (学习日记)2024.01.19
  • ***通过什么方式***网吧
  • ./configure、make、make install 命令
  • .[hudsonL@cock.li].mkp勒索病毒数据怎么处理|数据解密恢复
  • .net core 6 使用注解自动注入实例,无需构造注入 autowrite4net
  • .net 设置默认首页
  • .NET 自定义中间件 判断是否存在 AllowAnonymousAttribute 特性 来判断是否需要身份验证
  • .NET6实现破解Modbus poll点表配置文件
  • .net遍历html中全部的中文,ASP.NET中遍历页面的所有button控件
  • .net最好用的JSON类Newtonsoft.Json获取多级数据SelectToken
  • @RequestBody与@ModelAttribute
  • @RequestBody与@ResponseBody的使用