I\'m making a map app, including the location arrow that shows you which way you\'re facing, like so:
It seems that the appropriate way to get the bearing when the user is holding the phone vertically is to use something like this:
// after calling getRotationMatrix pass the rotationMatix below:
SensorManager.remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR);
If you want to handle both ways (vertical and flat) you will probably need to detect that and then only perform this remap when it is vertical.
See the API Documentation here.