0

我正在尝试检测 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));
};
4

1 回答 1

0

您的设备可能没有Sensor.TYPE_ROTATION_VECTOR

于 2013-04-16T19:10:42.337 回答