android 陀螺仪的使用

public class MainActivity extends Activity implements SensorEventListener{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		SensorManager sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); 
		Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
		sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI);
	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		Log.d("llx", " x:" + event.values[0] + " y:" + event.values[1]  + " z:" + event.values[2]);
	}

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO Auto-generated method stub
	}
}

 

上一篇:黑白间隔点巡线思路


下一篇:Flink从集合中读取数据并且输出出来