首页 > 代码库 > AndroidManifest.xml的<uses-feature>节点

AndroidManifest.xml的<uses-feature>节点

参考资料:http://developer.android.com/guide/topics/manifest/uses-feature-element.html

<uses-feature>标签位于<manifest>标签中,可以允许多个,用于声明应用依赖的硬件或者软件功能。但这仅限于声明,安装时并不会真正检查这些功能。真正代码中用到功能,还是需要通过PackageManager去判断当前环境是否支持。这些声明真正的目的是用于告诉外界应用是为怎么样的设备设计的,这可以让其他服务(比如应用商店)或者其他应用获取一些信息并与之交互,为合适的设备推荐合适的应用。

语法:

<uses-feature    android:name="string"    android:required=["true" | "false"]    android:glEsVersion="integer" />

 

属性:

android:name

依赖的硬件或软件功能名

android:required

如果为true,则表示这个设备的这个功能是必须的,应用缺少这个功能将无法正常运行。
如果为false,则表示这个设备的这个功能并非必须,应用缺少这个功能可以正常运行。
默认值为true

android:glEsVersion

如果应用需要依赖OpenGL ES,则需要在这里填版本号。版本号用一个整数表示,整数高16位表示大版本号,低16位表示小版本号,比如OpenGL ES 2.0的版本号为0x00020000。整个应用最多声明一个glEsVersion,如果有多处声明,则取版本号最大的那个。如果应用没有声明这个属性,则默认为OpenGL ES 1.0。OpenGL ES是向下兼容的,所以只需要声明需要版本最高的那个。

动态方式获取功能信息:

当应用运行时需要某个设备功能,需要先判断设备是否支持。通过PackageManager.getSystemAvailableFeatures方法可以获取设备所有支持的功能;通过PackageManager.hasSystemFeature方法可以判断设备是否支持某个功能。

通过PackageInfo.reqFeatures可以获取某个应用所有声明的功能依赖。

硬件功能表:

注意子功能需要父功能声明过,至少android:required="false"

音频
android.hardware.audio.low_latency
低延时音频通道,用于对延时比较铭感的场景。

蓝牙
android.hardware.bluetooth
蓝牙功能
android.hardware.bluetooth_le
蓝牙 4.0 LE(Bluetooth Smart)

摄像头
android.hardware.camera
摄像头功能
android.hardware.camera.autofocus
自动对焦
android.hardware.camera.flash
闪光灯
android.hardware.camera.front
前置摄像头
android.hardware.camera.any
任何方向的摄像头
android.hardware.camera.external
扩展摄像头

红外
android.hardware.consumerir
红外通信

定位
android.hardware.location
使用一种或者多种方式定位
android.hardware.location.network
使用网络定位
android.hardware.location.gps
使用gps定位

麦克风
android.hardware.microphone
麦克风功能

近场通信
android.hardware.nfc
近场通信功能
android.hardware.nfc.hce
HCE功能

传感器
android.hardware.sensor.accelerometer
加速器
android.hardware.sensor.barometer
气压计
android.hardware.sensor.compass
罗盘
android.hardware.sensor.gyroscope
陀螺仪
android.hardware.sensor.light
光线传感器
android.hardware.sensor.proximity
近程传感器
android.hardware.sensor.stepcounter
计步器
android.hardware.sensor.stepdetector
步伐检测器

屏幕
android.hardware.screen.landscape
横屏
android.hardware.screen.portrait
竖屏
如果应用支持两个方向,是不需要声明上面两个功能的。

电话
android.hardware.telephony
电话功能
android.hardware.telephony.cdma
cdma通话
android.hardware.telephony.gsm
gsm通话

电视
android.hardware.type.television
电视功能

触屏
android.hardware.faketouch
基本触屏功能,只能点击
android.hardware.touchscreen
支持手势的触摸功能。默认已经声明了这个功能,如果要声明应用可以支持非触摸,可以把required设为false
android.hardware.touchscreen.multitouch
两点触控
android.hardware.faketouch.multitouch.distinct
两点或者多点点击触控
android.hardware.faketouch.multitouch.jazzhand
五点或者更多点击触控
android.hardware.touchscreen.multitouch.distinct
两点或者多点触控
android.hardware.touchscreen.multitouch.jazzhand
五点或者更多触控

USB
android.hardware.usb.host
作为USB主机端口功能
android.hardware.usb.accessory
作为USB客户端功能

WIFI
android.hardware.wifi
使用wifi功能
android.hardware.wifi.direct
wifi直连功能

软件功能表:

android.software.app_widgets
提供桌面组件功能

android.software.device_admin
提供设备管理器功能

android.software.home_screen
提供自定义主屏程序功能

android.software.input_methods
提供自定义输入法功能

android.software.live_wallpaper
提供自定义动态壁纸功能

android.software.sip
提供SIP功能

android.software.sip.voip
提供模拟信号数字化功能

另外在代码中使用系统提供的硬件软件功能需要声明相应的权限,下面是功能和权限对照表:
http://developer.android.com/guide/topics/manifest/uses-feature-element.html#permissions

AndroidManifest.xml的<uses-feature>节点