我正在尝试检测 y 轴旋转角度(保持横向时向前向后倾斜)但我显然做错了,因为 onSensorChanged 事件永远不会被触发
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
mSensorManager.registerListener(this.mSensorEventListener, mSensor, SensorManager.SENSOR_DELAY_GAME);
}
...
private SensorEventListener mSensorEventListener = new SensorEventListener() {
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent event) {
float aX = event.values[1];
float aY = event.values[2];
double angle = aY * (Math.PI / 180);
btnStop.setText(Double.toString(angle));
};