本文实例讲述了Android基于Sensor感应器获取重力感应加速度的方法。,具体如下:
FETC项目指导老师提出了新的需求,想要在游戏地图中表现出用户用户当期移动的方向,再用GPS的话显然很不靠谱,所以想到了android强大的感应器。。。
很多移动设备都内置了感应器,android通过Sensor和SensorManager类抽象了这些感应器,通过这些类可以使用android设备的传感器
一 介绍Sensor类
SDK只有一句介绍“Class representing a sensor. Use getSensorList(int) to get the list of available Sensors.”,表示一个感应器的类,可以使用getSensorList方法(此方法属于接下来要讲的SensorManager)获得所有可用的感应器,该方法返回的是一个List<Sensor>
下面的列表显示了,Sensor所提供的所有服务
Constants
int TYPE_ACCELEROMETER A constant describing an accelerometer sensor type.
//三轴加速度感应器 返回三个坐标轴的加速度 单位m/s2
int TYPE_ALL A constant describing all sensor types.
//用于列出所有感应器
int TYPE_GRAVITY A constant describing a gravity sensor type.
//重力感应器
int TYPE_GYROSCOPE A constant describing a gyroscope sensor type
//陀螺仪 可判断方向 返回三个坐标轴上的角度
int TYPE_LIGHT A constant describing an light sensor type.
//光线感应器 单位 lux 勒克斯
int TYPE_LINEAR_ACCELERATION A constant describing a linear acceleration sensor type.
//线性加速度
int TYPE_MAGNETIC_FIELD A constant describing a magnetic field sensor type.
//磁场感应 返回三个坐标轴的数值 微特斯拉










