我试图在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状态。