How to determine the angle of the phone?

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

Now I go through the 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 depends on the rotation of the phone when it goes along the blue line.

How to count or how to get this angle?

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

How can I use SensorManager.getOrientation to control the tilt, such as "My Paper Plane"? , - the same question here, but I do not understand how the author solves his problem.

+3
source share
3 answers

The author of this question solved his problem by switching his order of parameters:

 if (SensorManager.getRotationMatrix(m_rotationMatrix, null,
                                    m_lastMagFields, m_lastAccels)) {

at

if (SensorManager.getRotationMatrix(m_rotationMatrix, null,
                                m_lastAccels, m_lastMagFields)) {
0
source

All Articles