I do not have an exact solution, but the solution with a full hole includes the TRIAD algorithm for combining a vector with a magnetometer (compass) and an accelerometer. This Wikipedia article is examined in detail in it.
, "" , . "" "". -, , , "".
/ , - . , .
EDIT: - Android-, , . Sensor TYPE_ORIENTATION SensorManager. , . , .