I made an extremely simple app that gets the exact angle in degrees of your android based phone / tablet device and displays the resulted values of azimuth, pitch, and roll in the TextView which can be used for Virtual Reality based apps. My next app that I will display will actually demonstrate this in a real 3D world done in OpenGL ES 3.0 (Coming Soon):

Java Code:
  1. import android.hardware.Sensor;
  2. import android.hardware.SensorEvent;
  3. import android.hardware.SensorEventListener;
  4. import android.hardware.SensorManager;
  5. import android.os.Bundle;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.view.WindowManager;
  8. import android.widget.TextView;
  9.  
  10. public class MainActivity extends AppCompatActivity implements SensorEventListener{
  11.  
  12.     private SensorManager sensorManager;
  13.  
  14.     float[] rotMatrix = new float[9];
  15.     float[] radianValues = new float[3];
  16.  
  17.     TextView textView;
  18.  
  19.     @Override
  20.     protected void onCreate(Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         setContentView(R.layout.activity_main);
  23.         getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  24.         sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
  25.         textView = findViewById(R.id.textView);
  26.     }
  27.  
  28.     @Override
  29.     protected void onPause() {
  30.         super.onPause();
  31.  
  32.         // Don't receive any more updates from either sensor.
  33.         sensorManager.unregisterListener(this);
  34.     }
  35.  
  36.     //when this Activity starts
  37.     @Override
  38.     protected void onResume()
  39.     {
  40.         super.onResume();
  41.  
  42.         sensorManager.registerListener(this , sensorManager.getDefaultSensor(Sensor.TYPE_GAME_ROTATION_VECTOR), SensorManager.SENSOR_DELAY_NORMAL);
  43.     }
  44.  
  45.     @Override
  46.     public void onSensorChanged(SensorEvent event) {
  47.         if (event.sensor.getType() == Sensor.TYPE_GAME_ROTATION_VECTOR) {
  48.                 SensorManager.getRotationMatrixFromVector(rotMatrix, event.values);
  49.                 SensorManager.remapCoordinateSystem(rotMatrix,
  50.                         SensorManager.AXIS_X, SensorManager.AXIS_Y, rotMatrix);
  51.                 SensorManager.getOrientation(rotMatrix, radianValues);
  52.                 float azimuth = (float) Math.toDegrees(radianValues[0]);
  53.                 float pitch = (float) Math.toDegrees(radianValues[1]);
  54.                 float roll = (float) Math.toDegrees(radianValues[2]);
  55.                 textView.setText(getString(R.string.vr, azimuth, pitch, roll));
  56.         }
  57.     }
  58.  
  59.     @Override
  60.     public void onAccuracyChanged(Sensor sensor, int accuracy) {
  61.  
  62.     }
  63. }