How to detect phone tilt?

user1367713 picture user1367713 · May 1, 2012 · Viewed 10.7k times · Source

How to determine the angle of the phone orientation in the one plane?

Now I make it through SensorManager:

mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);

...

public void onSensorChanged(SensorEvent event) {
    xy_angle = event.values[0]; 
    xz_angle = event.values[1]; 
    zy_angle = event.values[2]; 

Here I get different angles, but I need only one angle, which varies with the rotation of the phone, while driving along the blue line.

How calc or how get this angle?

http://i.stack.imgur.com/kCElj.jpg

How can I use SensorManager.getOrientation for tilt controls like "My Paper Plane"? - similar question here, but I don't understand how author solve his problem.

Answer

Krishnakant Dalal picture Krishnakant Dalal · May 1, 2012

What you need is SensorManager.getOrientation().