android程序中的AndroidManifest.xml中的uses-feature详解

AndroidManifest.xml中的uses-feature

Android的manifest文件:

用于指定android程序,是否需要某种硬件或软件资源/功能。

uses-feature的语法

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

android:name

  • 摄像头: android.hardware.camera
  • 各种传感器:
    • 加速计 :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.microphone
  • 定位: android.hardware.location
  • USB:
    • USB Host: android.hardware.usb.host
  • WIFI: android.hardware.wifi
  • 蓝牙: android.hardware.bluetooth
  • Bluetooth Low Energy: android.software.bluetooth_le
  • VOIP: android.software.sip.voip

http://developer.android.com/guide/topics/manifest/uses-feature-element.html#features-reference

android:required

  • android:required="true" :表示需要设备具有某个功能。
    • 如果设备没有该功能,则程序不工作,就是可以理解的
  • android:required="false" :表示希望设备,最好具有某个功能
    • 设备即使没有该功能,程序也应该可以正常工作
    • 为了程序工作的更好,最好具有该功能。

如果不指定,默认为true:

android:required="true":

android:qlEsVersion

  • OpenGL ES 1.0
  • OpenGL ES 2.0
  • OpenGL ES 3.0

我这里不涉及到,不去深究。

uses-feature写法举例

1.某程序需要蓝牙和摄像头,就可以这么写:

<uses-feature android:name="android.hardware.bluetooth" />
<uses-feature android:name="android.hardware.camera" />

2.如果,某个设备,是类似于照相机之类的程序,那么没有摄像头,就没法正常工作,则可以加上required参数为true:

<uses-feature android:name="android.hardware.camera" android:required="true" />

3.如果某个文件共享的软件,除了通过WIFI传输外,如果有蓝牙,那最好,也支持通过蓝牙传输,则可以加上required为false,希望最好有蓝牙:

<uses-feature android:name="android.hardware.bluetooth" android:required="false" />

4.比如,我的程序,是将android设备作为USB的Host,外接USB的设备的,所以要求必须有USB的host,所以可以写为:

<uses-feature android:required="true" android:name="android.hardware.usb.host" />

uses-feature的注意事项和其他说明

uses-feature,只是起到指示性的作用,不是强制的检测

uses-feature,只是起到指示性的作用,不是强制的检测

如果像上面的,我写了:

<uses-feature android:name="android.hardware.usb.host" android:required="true" />

[2013-11-05 10:15:37 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Parser exception for D:\DevRoot\xxxxxxxxxxxxxx\AndroidManifest.xml: Element type "uses-feature" must be followed by either attribute specifications, ">" or "/>". 

[2013-11-05 10:15:37 - yyyy] Error in an XML file: aborting build.

<uses-feature android:required="true" android:name="android.hardware.usb.host" />

本意是:希望此android设备必须有usb的host,否则没法工作。

即使没有usb的host,该app,也是可以在该android设备上面跑的

只不过不能正常工作罢了。

而作为Android系统,是不是强制去检测:

当此android设备,没有usb的host,就不让该app运行。

写android的app时最好还是加上合适的uses-feature的说明比较好

对于其他一些程序,比如Google Play

会根据你的程序中的uses-feature的声明,去过滤,分类android的app的。

另外,你的程序中,也最好,根据实际需要,去加上合适的uses-feature的说明,比较好。

方便用户和其他人明白,你的app对于资源的需求:

至少间接的相当于:给当前app,弄了个prerequisite前提条件了。

便于用户清楚需要哪些软硬件条件,才能运行你的当前的app。

可以用aapt去检测android的app(xxx.apk)中的uses-feature属性

Testing the features required by your application

adt-bundle-windows/sdk/platform-tools/aapt.exe

去拷贝了某个apk,测试了一把,结果如下:

CLi@PC-CLI-1 /cygdrive/d/DevRoot/android/adt-bundle-windows/sdk/platform-tools
$ ls
aapt.exe*  AdbWinApi.dll*     aidl.exe*  crifanLiTestAapt.apk*    crifanLiTestAapt_3.apk*  dx.bat*        lib/             NOTICE.txt*    source.properties*
adb.exe*   AdbWinUsbApi.dll*  api/       crifanLiTestAapt_2.apk*  dexdump.exe*             fastboot.exe*  llvm-rs-cc.exe*  renderscript/

CLi@PC-CLI-1 /cygdrive/d/DevRoot/android/adt-bundle-windows/sdk/platform-tools
$ ./aapt dump badging crifanLiTestAapt_3.apk
package: name='com.mm.xxxxxxx' versionCode='1' versionName='1.0'
sdkVersion:'14'
targetSdkVersion:'17'
uses-permission:'android.permission.WRITE_EXTERNAL_STORAGE'
uses-feature:'android.hardware.usb.host'
application-label:'MobileHandHeld'
application-label-zh:'某android应用程序'
application-icon-160:'res/drawable-mdpi/yyyyyyyyyy.png'
application-icon-240:'res/drawable-hdpi/yyyyyyyyyy.png'
application-icon-320:'res/drawable-xhdpi/yyyyyyyyyy.png'
application-icon-480:'res/drawable-xxhdpi/yyyyyyyyyy.png'
application: label='MobileHandHeld' icon='res/drawable-mdpi/yyyyyyyyyy.png'
launchable-activity: name='com.mm.xxxxxxx.activities.DeviceListActivity'  label='MobileHandHeld' icon=''
uses-permission:'android.permission.READ_EXTERNAL_STORAGE'
uses-implied-permission:'android.permission.READ_EXTERNAL_STORAGE','requested WRITE_EXTERNAL_STORAGE'
uses-feature:'android.hardware.touchscreen'
uses-implied-feature:'android.hardware.touchscreen','assumed you require a touch screen unless explicitly made optional'
uses-feature:'android.hardware.screen.landscape'
uses-implied-feature:'android.hardware.screen.landscape','one or more activities have specified a landscape orientation'
main
other-activities
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--' 'zh'
densities: '160' '240' '320' '480'


AndroidManifest.xml中的<uses-feature>以及和<uses-permission>之间的联系

概述:<uses-feature>用来声明应用中需要用的硬件和软件的功能。

硬件特性:表明您的应用需要用的硬件功能。

功能类型 特征描述 描述
音频 android.hardware.audio.low_latency 该应用程序使用低延迟的音频设备上的管道,声音输入或输出延迟或滞后敏感。
蓝牙 android.hardware.bluetooth 该应用程序使用蓝牙无线功能,在设备中。
相机 android.hardware.camera 该应用程序使用该设备的摄像头。如果设备支持多个摄像头,应用程序使用相机,面对从屏幕上移开。
  android.hardware.camera.autofocus 子功能。该应用程序使用设备相机的自动对焦能力。
  android.hardware.camera.flash 子功能。该应用程序使用设备相机的闪光灯。
  android.hardware.camera.front 子功能。该应用程序使用设备上的前置摄像头。
  android.hardware.camera.any 该应用程序使用至少一个摄像头朝向任何方向。使用当前在偏好android.hardware.camera的,如果不需要的背面朝相机。
位置 android.hardware.location 该应用程序使用设备上的一个或多个特征,确定位置,如GPS定位,网络位置或细胞的位置。
  android.hardware.location.network 子功能。该应用程序使用从设备支持的基于网络的地理定位系统获得的粗略的位置坐标
  android.hardware.location.gps 子功能。该应用程序使用设备上的全球定位系统接收器获得的精确位置坐标。
麦克风 android.hardware.microphone 该应用程序使用设备上的麦克风。
NFC android.hardware.nfc 该应用程序使用近场通讯在设备的收音功能。
传感器 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.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.faketouch.multitouch.distinct 不同的应用程序执行跟踪的两个或两个以上的“手指”上假的触摸界面。这是的faketouch功能的一个超集。
  android.hardware.faketouch.multitouch.jazzhand 不同的应用程序执行的跟踪5个或以上的“手指”上假的触摸界面。这是的faketouch功能的一个超集。
  android.hardware.touchscreen 该应用程序使用的触摸屏功能,比基本触摸事件,如一扔,更具互动性的手势。这是的基本faketouch功能的一个超集。
  android.hardware.touchscreen.multitouch 应用程序使用在设备屏幕上的两个基本点的多点触控功能,如捏的手势,但,不需要独立跟踪触及。这是触摸屏功能的一个超集。
  android.hardware.touchscreen.multitouch.distinct 子功能。在设备屏幕上的应用程序采用了先进的多点多点触控功能,如跟踪两个或两个以上的点完全独立。这是一个多点触控功能的超集。
  android.hardware.touchscreen.multitouch.jazzhand 在设备屏幕上的应用程序采用了先进的多点多点触控功能,跟踪到五点完全独立。这是一个独特的多点触控功能的超集。
USB android.hardware.usb.host 该应用程序使用USB主机模式功能(表现为主机和USB设备连接到)。
  android.hardware.usb.accessory 该应用程序使用的USB附件功能(表现为USB设备连接到USB主机)。
无线上网 android.hardware.wifi 应用程序使用802.11网络(WIFI)功能的设备上的。
     

软件功能:表明您的应用程序使用或需要的软件功能。

特点 属性值 描述
应用程序! android.software.app_widgets 该应用程序使用或提供应用小工具,仅应安装的设备上,包括一个主屏幕或类似的位置,用户可以应用小工具嵌入。
蓝牙低功耗 android.software.bluetooth_le

该应用程序使用蓝牙低能量的API只能够与其他设备通过蓝牙低功耗通信设备,应安装。这也隐含声明的android.hardware.bluetooth功能。

主屏幕 android.software.home_screen 主屏幕更换应用程序的行为,应只安装在设备主屏幕上的应用程序支持第三方。
输入法 android.software.input_methods 该应用程序提供了一个自定义的输入法应该只能安装在设备支持第三方输入法。
动态壁纸 android.software.live_wallpaper 该应用程序使用或提供动态壁纸,应该只能安装在设备支持动态壁纸。
SIP / VOIP android.software.sip 该应用程序使用SIP服务在设备上,只应安装上支持SIP的设备。
  android.software.sip.voip

子功能。该应用程序使用基于SIP的VoIP服务在设备上。

此子功能隐式声明android.software.sip的父特征,除非宣布与

android:required="false"
     

权限和功能之间的联系:

类别 需要的权限 要求的功能
蓝牙 BLUETOOTH android.hardware.bluetooth

(见特殊处理的蓝牙功能的详细信息。)

  BLUETOOTH_ADMIN android.hardware.bluetooth
相机 CAMERA android.hardware.camera  
android.hardware.camera.autofocus
位置 ACCESS_MOCK_LOCATION android.hardware.location
  ACCESS_LOCATION_EXTRA_COMMANDS android.hardware.location
  INSTALL_LOCATION_PROVIDER android.hardware.location
  ACCESS_COARSE_LOCATION android.hardware.location.network  
android.hardware.location
  ACCESS_FINE_LOCATION android.hardware.location.gps  
android.hardware.location
麦克风 RECORD_AUDIO android.hardware.microphone
电话 CALL_PHONE android.hardware.telephony
  CALL_PRIVILEGED android.hardware.telephony
  MODIFY_PHONE_STATE android.hardware.telephony
  PROCESS_OUTGOING_CALLS android.hardware.telephony
  READ_SMS android.hardware.telephony
  RECEIVE_SMS android.hardware.telephony
  RECEIVE_MMS android.hardware.telephony
  RECEIVE_WAP_PUSH android.hardware.telephony
  SEND_SMS android.hardware.telephony
  WRITE_APN_SETTINGS android.hardware.telephony
  WRITE_SMS android.hardware.telephony
无线上网 ACCESS_WIFI_STATE android.hardware.wifi
  CHANGE_WIFI_STATE android.hardware.wifi
  CHANGE_WIFI_MULTICAST_STATE android.hardware.wifi

猜你喜欢

转载自blog.csdn.net/u010823818/article/details/54288045