这是检查系统上是否存在指南针传感器的正确方法吗?

时间:2018-08-04 17:25:08

标签: android android-sensors

我试图用给定的方法检查罗盘传感器这么长时间。请告诉我以下是否正确:

SensorManager m = getSensorManager();
if (!m.hasSystemFeature(SensorManager.FEATURE_SENSOR_COMPASS)) {
    //
}

1 个答案:

答案 0 :(得分:2)

FEATURE_SENSOR_COMPASSSensorManager上不是常数。是a constant on PackageManager

the documentation所示,您可以使用PackageManager.FEATURE_SENSOR_COMPASS来确定是否有磁力计传感器(通常用于实施指南针):

PackageManager pm = getPackageManager();
if (!pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) {
    // This device does not have a compass, turn off the compass feature
    disableCompassFeature();
}