Android 传感器(Sensor)API教程 (二) 传感器事件

来源:互联网 发布:linux 命令行 用户名 编辑:程序博客网 时间:2024/05/19 15:23

原帖地址:http://www.androidegg.com/portal.php?mod=view&aid=592

1.3.4  android.hardware.SensorEvent 

     SensorEvent类是在传感器事件(onAccuracyChanged  , onSensorChanged 稍后介绍)为了对能取得的信息进行整理管理的类。被管理的值全部用公用的field定义的。

●主要的字段(field)
SensorEvent类的主要的field如表1-5所示
                              表1-5    SensorEvent类的主要的field
字段(field)
内容
public int accuracy
传感器的精度
public Sensor sensor
传感器的instance
public long timestamp
时间(毫微秒)
public final flaot[] values
传感器的值

    1.3.5  android.hardware.SensorEventListener接口
   
SensorEventListener接口是为了取得传感器的事件的事件监听器。前面所说的
SensorManager类具有登录删除功能。在这个封装的接口中可以取得传感器的值。

●主要的事件
方法
处理内容
void onAccuracyChanged(Sensor sensor,int accuracy)
传感器的精度变化的时候,此方法被调用
void onSensorChanged(SensorEvent event)
传感器的值改变的时候,此方法被调用

原创粉丝点击