dino368
dino368

Reputation: 17

getRotationMatrix always false and solutions don't work

I am trying out to detect a rotation, not a screen orientation change.

I only got a false on getRotationMatrix().

I found a solution here but it didn't work for me.

@Override
public void onSensorChanged(SensorEvent event) {
    // This method will be called when the accelerometer values are changing.
    if (event == null || event.values.length == 0) throw new IllegalArgumentException();
    else {
        // Handle the events for which we registered
        switch (event.sensor.getType()) {
            case Sensor.TYPE_ACCELEROMETER:
                Log.i(TAG, "detected Accelerometer");
                    mValuesAccel =  event.values;

                break;

            case Sensor.TYPE_MAGNETIC_FIELD:
                Log.i(TAG, "detected Magneticfield");
                    mValuesMagnet = event.values;

                break;
        }

        Log.i(TAG, ""+ SensorManager.getRotationMatrix(mRotationMatrix, null, mValuesAccel, mValuesMagnet));
        SensorManager.getOrientation(mRotationMatrix, mValuesOrientation);

        mRotationListener.onChange(mValuesOrientation);

    }

}

Upvotes: 0

Views: 448

Answers (1)

agamov
agamov

Reputation: 4427

Check if your device has a compass. If there's no compass then your mValuesMagnet is always empty and as a result getRotationMatrix returns false.

Upvotes: 2

Related Questions