Get tilt angle from the android accelerometer

user1615888 picture user1615888 · Aug 22, 2012 · Viewed 12.9k times · Source

I have a class that implements SensorEventListener and I would like to get the tilt Angle of my device using the Accelerometer.

I looked for examples on the internet but they use Sensor.TYPE_MAGNETIC_FIELD.

I believe my device doesn't have this sensor because when I do the following check
manager.getSensorList(Sensor.TYPE_ACCELEROMETER).size(), I get zero.

Is there a way to get the tilt Angle by just using Sensor.TYPE_ACCELEROMETER values?

Answer

Gurinder Singh picture Gurinder Singh · Mar 22, 2015

As people suggested you can use the accelerometer and magnetic sensor to do this.

Here is a blog post with a complete solution.

http://www.ahotbrew.com/how-to-detect-forward-and-backward-tilt/