calculating angle - android

I've been trying to figure this out, but with no luck.

I want to calculate the angle between the phone's orientation and the y-axis, when rotating the phone around the z-axis. I'm holding the phone in front of me and tilting it from portrait orientation towards landscape landscape orientation, with the y-axis running through the center of the earth. Now I want the angle of the tilt. I had made a picture explaining what angle I need, but I needed more reputation to post images...

Now I want to know what sensor type to use and which value. In my tries I haven't been able to isolate just that specific angle. The closest one I got was TYPE_ROTATION_VECTOR with value[2] but I didn't get that to work fully, and besides, you needed api level 9 for that.


  • What you need is SensorManager.getOrientation()