Android Sensor感应器介绍(三)Sensor类介绍


  
DK只有一句介绍“Class representing a sensor. UsegetSensorList(int) to get the list of availableSensors.”,表示一个 感应器的类,可以使用getSensorList方法(此方法属于接下来要讲的SensorManager)获得所有可用的感应器,该方法返回的是一个 List

下面显示了Sensor所提供的所有服务
Constants
int  TYPE_ACCELEROMETER  A constant describing an accelerometer sensortype. //三轴加速度感应器 返回三个坐标轴 的加速度 单位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 accelerationsensor type. //线性加速度
int TYPE_MAGNETIC_FIELD  Aconstant describing a magnetic field sensor type.//磁场感应返回三个
坐标轴的数值 微特斯拉
int TYPE_ORIENTATION  Thisconstant is deprecated. use SensorManager.getOrientation() instead.//方向感应器 已 过时可以使用方法获得
int  TYPE_PRESSURE  A constant describing a pressure sensor type//压力感应器 单位  千帕斯卡
int TYPE_PROXIMITY   Aconstant describing an proximity sensortype.//距离传感器
int   TYPE_ROTATION_VECTOR  A constant describing a rotation vector sensortype.//翻转传感器
int   TYPE_TEMPERATURE A constant describing a temperature sensor type//温度传感器 单位 摄氏

此类中包含的方法都是get型的用来获取所选sensor的一些属性,sensor类一般不需要new而是通过SensorManager的方法获得


二 介绍SensorManager类

SDK解释:“SensorManager lets you access thedevice's sensors. Get an instance of this class bycalling  Context.getSystemService()with the argument SENSOR_SERVICE.
Always make sure to disable sensors you don'tneed, especially when your activity is paused. Failing to do socan drain the battery in just a few hours. Notethat the system will not disable sensors automatically when thescreen turns off. ”

SensorManager允许你访问设备的感应器。通过传入参数SENSOR_SERVICE参数调用Context.getSystemService方法可以获得一个 sensor的实例。永远记得确保当你不需要的时候,特别是Activity暂定的时候,要关闭感应器。忽略这一点肯能导致几个小时就耗尽 电池,注意当屏幕关闭时,系统不会自动关闭感应器。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值