Add a handler function when gravity changes
The function dosomething (x, y, z) that is called when the listener is created is a method that is defined by itself.
The listener calls this method when the phone's tilt direction changes.
All we have to do is populate the method to do our own processing when gravity changes.
When x=y=0, the phone is placed in a horizontal position.
When X=0 and Y>0, the top of the phone's horizontal position is greater than the bottom, that is, the general answer to the phone when the phone is in the state.
When X=0 and y<0, the horizontal position of the top of the phone is smaller than the bottom. Mobile phones are rarely in this state.
When Y=0 and x>0, the horizontal position on the right side of the phone is greater than the left side, i.e. the right side is lifted.
When Y=0 and x<0, the horizontal position on the right side of the phone is smaller than the left side, that is, the left side is lifted.
When z=0, the cell phone plane is perpendicular to the horizontal plane.
When z>0, the phone screen is facing up.
When z<0, the phone screen faces down.
Android Gravity sensor sensor programming