summary:
- import android.hardware.*;
- SensorManager mSensorManager;
- Sensor accSensor, gyroSensor;
- mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
- accSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
- gyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
- implements SensorEventListener
- public void onSensorChanged(SensorEvent event) { ... }
- mSensorManager.registerListener(this, accSensor, SensorManager.SENSOR_DELAY_UI);
- mSensorManager.registerListener(this, gyroSensor, SensorManager.SENSOR_DELAY_UI);
- get the x, y, z values using event.values[0], [1], [2] in the onSensorChanged method
- mSensorManager.unregisterListener(this, accSensor);
- mSensorManager.unregisterListener(this, gyroSensor);
No comments:
Post a Comment