从android加速度计获取倾斜角度 [英] Get tilt angle from the android accelerometer
问题描述
我有一个实现 SensorEventListener
的类,我想获得
的倾斜角
我的设备使用加速度计
。
I have a class that implements SensorEventListener
and I would like to get
the tilt Angle
of my device using the Accelerometer
.
我在互联网上寻找示例,但是他们使用
Sensor.TYPE_MAGNETIC_FIELD
。
I looked for examples on the internet but they use
Sensor.TYPE_MAGNETIC_FIELD
.
我相信我的设备没有此传感器,因为当我在检查后执行
时
manager .getSensorList(Sensor.TYPE_ACCELEROMETER).size()
,我得到零。
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.
有没有办法只需使用
Sensor.TYPE_ACCELEROMETER
值获得倾斜角
?
Is there a way to get the tilt Angle
by just using
Sensor.TYPE_ACCELEROMETER
values?
推荐答案
正如人们所建议的,您可以使用加速度计和磁性传感器来做到这一点。
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/
这篇关于从android加速度计获取倾斜角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!