title: How can accelerator and Magnetic Field type be extracted this way?
body: <p>I am make an app for my university project by measuring the tilt angle of the phone when a person holds it. I found this code for finding a phone's tilt angle. </p>
  
  <p>How can <code>event.sensor.getType()</code> be 1 for accelerometer and 2 for Magnetic field at the same time? It is an integer value. This code always returns without executing since the <code>event.sensor.getType()</code> value is always 1. The code exists at <strong>if (mGravity != null &amp;&amp; mGeomagnetic != null) {</strong></p>
  
  <p>I use a Nexus 4 phone with Android 5.0.1</p>
  
  <p>Please tell me if I'm doing something wrong. I've registered the sensors in the prescribed way.</p>
  
  <pre><code>    float[] mGravity = null;
      float[] mGeomagnetic = null;
      float playerAngle1 = 0;
      float playerAngle2 = 0;
  
      **if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
          mGravity = event.values;
      if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
          mGeomagnetic = event.values;**
  
      if (mGravity != null &amp;&amp; mGeomagnetic != null) {
  
          float R[] = new float[9];
          float I[] = new float[9];
  
          for (int i = 0; i &lt; 3; i++) {
              System.out.println(mGravity[i]);
          }
  
          for (int i = 0; i &lt; 3; i++) {
              System.out.println(mGeomagnetic[i]);
          }
  
          System.out.println();
          System.out.println();
  
          boolean success = SensorManager.getRotationMatrix(R, I, mGravity,  mGeomagnetic);
  
          if (success) {
  
              System.out.println("getRotationMatrix");
  
              float orientation[] = new float[3];
              SensorManager.getOrientation(R, orientation);
              playerAngle1 = (float) Math.toDegrees(Math.atan2(orientation[1], orientation[0]));
              playerAngle2 = (float) Math.toDegrees(orientation[1]);
              System.out.println("Angle1 :" + playerAngle1);
              System.out.println("Angle2 :" + playerAngle2);
  
          }
      }
  </code></pre>