Taher
Taher

Reputation: 1245

Measuring exact rotation angle of device in android

I need to get exact angle of my android device from each axis.

First I should say I searched through web and also stackoverflow and I saw pages like these:

How to measure the tilt of the phone in XY plane using accelerometer in Android

Get Android rotation angle in x-axis

But they were not helpful. I used some of them but they give wrong values.

If the axis in device will be like this:

enter image description here

I need to get these rotation angle:

enter image description here

I don't want to use any hardware sensor except accelerometer and I work with API 17. I think this is possible based on racing games, but I don't know how to do that.

I will appreciate if you help me. Thanks

Upvotes: 4

Views: 4394

Answers (1)

Hoan Nguyen
Hoan Nguyen

Reputation: 18151

There is no way you can get all the rotations using TYPE_ACCELEROMETER alone. You also need TYPE_MAGNETIC_FIELD. If you do not care about how sensitive the values changed with respect to quick movement then you need TYPE_GRAVITY or TYPE_ACCELEROMETER together with TYPE_MAGNETIC_FIELD.
For rotation with respect to the z-axis you can follow the first link in your question.
For rotation with respect to the x and y axes you can use pitch and roll and screen facing.

Upvotes: 1

Related Questions