Android:检索 phone 角度的准确方法?

Android: Accurate way to retrieve the phone's angle?

有没有办法检索 Android phone 的角度?如果我把我的 phone 平放在 table 上,角度应该是 0 度,如果我把我的 phone 竖直靠在墙上,角度应该是 90 度。我想知道我是否可以利用 phone 硬件中内置的任何传感器来完成此操作。

Position sensors are useful for determining a device's physical position in the world's frame of reference. For example, you can use the geomagnetic field sensor in combination with the accelerometer to determine a device's position relative to the magnetic north pole. You can also use these sensors to determine a device's orientation in your application's frame of reference. Position sensors are not typically used to monitor device movement or motion, such as shake, tilt, or thrust (for more information, see Motion sensors).

....Pitch (degrees of rotation about the x axis). This is the angle between a plane parallel to the device's screen and a plane parallel to the ground. If you hold the device parallel to the ground with the bottom edge closest to you and tilt the top edge of the device toward the ground, the pitch angle becomes positive. Tilting in the opposite direction— moving the top edge of the device away from the ground—causes the pitch angle to become negative. The range of values is -180 degrees to 180 degrees.

https://developer.android.com/guide/topics/sensors/sensors_position