我试图用给定的方法检查罗盘传感器这么长时间。请告诉我以下是否正确:
SensorManager m = getSensorManager();
if (!m.hasSystemFeature(SensorManager.FEATURE_SENSOR_COMPASS)) {
//
}
答案 0 :(得分:2)
FEATURE_SENSOR_COMPASS
在SensorManager
上不是常数。是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();
}