Found its answer:
Calculate azimuth angle like this:
mAzimuthAngleNotFlat = (int) Math.toDegrees(Math
.atan2((rotationMatrix[1] - rotationMatrix[3]), (rotationMatrix[0] + rotationMatrix[4])));
To convert it to 0 to 359 simply apply this:
if (mAzimuthAngleNotFlat < 0) {
mAzimuthAngleNotFlat += 360;
}
Then you are done. And this angle will be accurate when device is not flat. For more, you can see discussion on accepted answer.
Inconsistent orientation sensor values on Android for azimuth/yaw and roll