title: android get angle of device in flat
body: <p>Which is the inclination of the moving angle to an angle 0 which corresponds to mobile laid flat.
  I want exactly measure angle on the corner walls (between 2 walls)</p>
  
  <p>I already use this code, and the results obtained:</p>
  
  <pre><code>public void onAccuracyChanged(Sensor sensor, int accuracy) {
  
      float[] mGravity;
      float[] mGeomagnetic;
      public void onSensorChanged(SensorEvent event){
        if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
             mGravity = event.values.clone();
        }
        if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
            mGeomagnetic = event.values.clone();
        if (mGravity != null &amp;&amp; mGeomagnetic != null) {
          float R[] = new float[9];
          float I[] = new float[9];
          boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
          if (success) {
            float orientation[] = new float[3];
            SensorManager.getOrientation(R, orientation);
            azimut = orientation[0]; 
            mAzimuthView.setText(String.format("%.2f",Math.toDegrees(azimut)) + '°');
            tv.setText(String.format("%.2f", Math.toDegrees(azimut-angle_reset)) + '°');
          }
      }
  
  }
  </code></pre>
  
  <p>1 - GSM is a flat vertical -> azimuth = 37 ° .
  2 - Turn GSM Horizontally 90 ° -> = -111 ° azimuth .
  So the difference ( 111-37 ) is 74 ° !!!! ( But normally I have to get 90 °)</p>