我建议编写一些代码来查询 Android 的 SensorManager 对象。例如,尝试以下
SensorManager sm = (SensorManager)getSystemService(android.content.Context.SENSOR_SERVICE);
List<Sensor> sensorlist = sm.getSensorList(Sensor.TYPE_ALL);
for(Sensor sens : sensorlist) {
Log.d("TEST", "Name="+sens.getName()+",Type="+sens.getType());
}
Sensor SensorGyro = sm.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
Log.d("TEST", (SensorGyro == null ? "SensorGyro==null":"Name="+SensorGyro.getName()+",Type="+SensorGyro.getType()));
并使用输出来帮助找出问题所在。我在我的 Galaxy Note 2 上运行了它,它产生了:
05-07 14:42:38.585: D/TEST(6160): Name=LSM330DLC Acceleration Sensor,Type=1
05-07 14:42:38.585: D/TEST(6160): Name=AK8963C Magnetic field Sensor,Type=2
05-07 14:42:38.585: D/TEST(6160): Name=LSM330DLC Gyroscope Sensor,Type=4
05-07 14:42:38.585: D/TEST(6160): Name=BMP182 Barometer Sensor,Type=6
05-07 14:42:38.585: D/TEST(6160): Name=CM36651 Proximity Sensor,Type=8
05-07 14:42:38.585: D/TEST(6160): Name=CM36651 Light Sensor,Type=5
05-07 14:42:38.585: D/TEST(6160): Name=Rotation Vector Sensor,Type=11
05-07 14:42:38.585: D/TEST(6160): Name=Gravity Sensor,Type=9
05-07 14:42:38.585: D/TEST(6160): Name=Linear Acceleration Sensor,Type=10
05-07 14:42:38.585: D/TEST(6160): Name=Orientation Sensor,Type=3
05-07 14:42:38.585: D/TEST(6160): Name=Corrected Gyroscope Sensor,Type=4
05-07 14:42:38.585: D/TEST(6160): Name=LSM330DLC Gyroscope Sensor,Type=4
所以那部手机上似乎有两个 Gysoscope 传感器。