1、为了能让你的应用程序根据设备特性来管理其可用性,Android对一些不是所有设备都可用的硬件和软件功能定义了一些id。例如,你的应用程序在一个缺乏指南针传感器的设备上是没有意义的,那么你可以在清单文件中如下声明:
<manifest ... > <uses-feature android:name="android.hardware.sensor.compass" android:required="true" /> ... </manifest>但是,如果你应用程序中的主要功能并不需要这种设备功能,你可以将required设置为false,并在运行时检查设备的功能,使用hasSystemFeature(),例如:
PackageManager pm = getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) { // This device does not have a compass, turn off the compass feature disableCompassFeature(); }注意:并且一些功能是隐式要求设备的功能,例如你的应用程序需要蓝牙的应用权限,这隐含着feature_bluetooth的要求,你可以禁用基于该设备特性的功能对那些没有蓝牙功能的设备并且让你的应用程序可以让没有蓝牙的设备下载通过在<user-feature>设置require为false