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
}
}
标签:陀螺仪,public,SensorManager,values,使用,Override,android,Sensor,event 来源: https://blog.51cto.com/u_15298588/3034194