I need something very simple, but I could not find a suitable example to learn from. My sole purpose is the following:
As the device is placed flat (on its back) on the desk, it should show 0 (or close to 0) for X and Y axis. When I lift it from the top part (where the speaker is) and the bottom part (where the microphone is) stays put down - it should show me how many degrees is the phone tilted. Mathematically described - show in degrees the angle between the back of the phone and the table, for one of the axises. When I lift the bottom part (and the top part stays put down) then show minus degrees.
The same goes for the other axis - rotating the phone around its long sides.
I tried assembling an app from different examples, using Gyroscope or Accelerometer or Rotation Vector Sensors, but could not come with something working properly.
Can someone give me an example of the onSensorChanged
function (as all the work goes on in here) and just tell me which sensor is used, so I know what to register?