在Android中无法使用陀螺仪

时间:2013-02-21 11:15:57

标签: android android-sensors gyroscope

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

0 个答案:

没有答案