Search code examples
androidrotationorientationsensormanager

getting the orientation(Roll, Pitch, Yaw) angles of the mobilePhone using Sensor Manager?


I'm trying to get the orientation (Roll, Pitch, Yaw) angles of the mobilePhone using Sensor Manager ,and according to what is written in android developers website, the method

getInclination(float[] I) Computes the geomagnetic inclination angle in radians from the inclination matrix I >returned by getRotationMatrix(float[], float[], float[], float[]).` and getRotationMatrix(float[] R, float[] I, float[] gravity, float[] geomagnetic)

Computes the inclination matrix I as well as the rotation matrix R transforming a vector >from the device coordinate system to the world's coordinate system which is defined as a >direct orthonormal basis. ` and it returns boolean value.

My question is, How to get the orientation using the methods mentioned?

Code

@Override
public void onSensorChanged(SensorEvent event) {
    // TODO Auto-generated method stub

    float []I = new float[9];
    float []R = new float[9];

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        float x = event.values[0];
        float y = event.values[1];
        float z = event.values[2];

        tvX.setText(Float.toString(x));
        tvY.setText(Float.toString(y));
        //tvZ.setText(Float.toString(sm.getInclination(I)));    
    }
}

Solution

  • Display disp = (Display)getSystemService(Context.WINDOW_SERVICE);
    int orientation = disp.getOrientation();
    

    Use the above two lines to get orientation of mobile phone