【Android编程】AndroidManifest.xml中的 <users-feature>

78 阅读2分钟

开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第32天,点击查看活动详情.

简述:

  <users-feature>用于指定android应用程序是否需要某个硬件或软件资源的支持,否则不能正常运行。users-feature 标签的目的是用来描述当前 app 所依赖的硬件或软件的功能有哪些, 是用来确保你手机有某硬件或软件的支持,并不负责向系统去请求权限。

属性:

  • 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 host:android.hardware.usb.host

    WIFI:android.hardware.wifi

    蓝牙:android.hardware.bluetooth

软件方面有:

  Bluetooth Low Energy:android.software.bluetooth_le

  VOIP:android.software.sip.voip

  • android.required="true/false" 表示是否需要某个功能。

  android:required属性表示这项feature是否是必须的,它的值只能是true或者false。如果设置为true表示这项feature是必须的,如果没有,应用将无法工作。如果设置为false,表示应用需要这项feature,但如果没有,可能会影响部分功能,但应用还是能够正常工作的。如果没有指定这项属性,则默认为true,即表示此feature是必须的。

  • android:glEsVersion

图片

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

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

——即使程序不具有uses-feature指定的软硬件资源,也不影响启动,只是会影响该功能的正常使用。

总结

就如给应用贴上一个标签,方便了解app的资源需求与分类。

例如:

    GooglePlay 会根据uses-feature的声明 过滤、分类app。