Search code examples
androidrotationdetection

How to detect android device rotation parallel to the ground?


As I know, the most of android devices allows to detect rotation by accelerometer, but I've noticed, that it doesn't detect rotation parallel to the ground. For example, if I put the device on a table and turn it around, no one of accelerometer indicators doesn't change.

enter image description here

At the picture, it's called "alfa" rotation. So how can I detect this kind of turning?


Solution

  • For sensing rotation around z-axis you need to implement a compass function. A good tutorial is this one. To make the resulting values more stable you need to implement some algorithm which smoothes your incoming data (averages over a queue of data, filtering outliers, etc.). Here is a good overview.