天天看点

Android -- Sensor传感器

Sensor创建步骤                                                                         

获取系统服务(SENSOR_SERVICE)返回一个SensorManager 对象

通过SensorManager对象获取相应的Sensor类型的对象

声明一个SensorEventListener 对象用于侦听Sensor 事件,并重载onSensorChanged方法

注册相应的SensorService

销毁相应的SensorService

传感器类型                                                                                  

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.//磁场感应 返回三个坐标轴的数值  微特斯拉

int TYPE_ORIENTATION  This constant is deprecated. use SensorManager.getOrientation() instead. //方向感应器 已过时 可以使用方法获得

int  TYPE_PRESSURE   A constant describing a pressure sensor type //压力感应器  单位 千帕斯卡

int TYPE_PROXIMITY   A constant describing an proximity sensor type.//距离传感器

int   TYPE_ROTATION_VECTOR   A constant describing a rotation vector sensor type.//翻转传感器

int   TYPE_TEMPERATURE  A constant describing a temperature sensor type //温度传感器 单位 摄氏度

程序代码                                                                                   

Android -- Sensor传感器
Android -- Sensor传感器

我是天王盖地虎的分割线                                                                

传感器.zip

本文转自我爱物联网博客园博客,原文链接:http://www.cnblogs.com/yydcdut/p/3829973.html,如需转载请自行联系原作者

继续阅读