The coordinate system of the Android sensor is not the same as its 2D design, with coordinate systems such as:
Once the sensor listener is registered with the Sensormanager object, an object of sensorevent can be obtained within the Onsensorchanged method.
The Sensorevent object has an important member variable public final float[] values, which are defined as follows:
Public final float[] values
The length and contents of the values
array depends on which sensor
type is being monitored
If the registration listener is an accelerometer, the values in the
Sensor.TYPE_ACCELEROMETER
:
All values is in SI units (m/s^2)//SI is the meaning of the international unit, which is the same unit as the acceleration of high school
values[0]: Acceleration minus Gx on the x-axis values[1]: Acceleration minus Gy on the y-axis values[2]: Acceleration minus Gz on the z-axis
You can see that the value of values[0~2] is a certain direction acceleration (acceleration) minus the gravity value in that direction (Gx, Gy, Gz), so the phone is stationary when its range is [ -10,10]
For example, the mobile phone screen is placed flat, then values[0]=0,values[1]=0,values[2]=10
Since the mobile phone is stationary and there is no acceleration in all directions, the cell phone flat puts the gravitational acceleration downward, i.e. gz=-10 (because the gravity direction is opposite to the z axis), so subtract 10