我正在尝试在 Android 中使用陀螺仪。
这是我的代码
//on the onCreate method
sensor = (SensorManager) getSystemService(SENSOR_SERVICE);
//the on onSensorChanged method
@Override
public void onSensorChanged(SensorEvent event) {
Sensor sensor = event.sensor;
if(sensor.getType() == Sensor.TYPE_GYROSCOPE){
Log.i("test", "TYPE_GYROSCOPE event");
}
}
//the onResume method
protected void onResume(){
super.onResume();
Sensor Accel = sensor.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
sensor.registerListener((SensorEventListener) this, Accel, SensorManager.SENSOR_DELAY_FASTEST);
}
但它不起作用,它永远不会进入 Sensor.TYPE_GYROSCOPE 条件。