Android 重力传感器值增加
每次调用Android 重力传感器值增加,android,Android,每次调用onSensorChanged(SensorEvent事件)事件值后,重力传感器值都会增加。值增加,经过一小段时间(约1分钟)后达到NaN值。有人能说出为什么会发生这种情况吗? 代码: 专用无效记录数据(传感器事件e){ 字符串标签; int currentSensorId=-1; 开关(e.sensor.getType()){ 外壳传感器.U型加速计: currentSensorId=0; 标签=日志标签加速度计; 打破 外壳传感器。U型陀螺仪: label=LOG\U label\U
onSensorChanged(SensorEvent事件)
事件值后,重力传感器值都会增加。值增加,经过一小段时间(约1分钟)后达到NaN值。有人能说出为什么会发生这种情况吗?
代码:
专用无效记录数据(传感器事件e){
字符串标签;
int currentSensorId=-1;
开关(e.sensor.getType()){
外壳传感器.U型加速计:
currentSensorId=0;
标签=日志标签加速度计;
打破
外壳传感器。U型陀螺仪:
label=LOG\U label\U陀螺仪;
currentSensorId=1;
打破
外壳传感器。类型_重力:
label=对数\标签\重力;
currentSensorId=2;
打破
案例传感器。类型\旋转\向量:
label=对数\标签\旋转\向量;
currentSensorId=3;
打破
违约:
label=“未知传感器类型!”;
打破
}
如果(currentSensorId==-1)
返回;
//强制将事件频率设置为配置中的值,
//导致传感器事件的最小频率=0.2秒。
timePassed[currentSensorId]=System.currentTimeMillis()
-lastSensorEventTime[currentSensorId];
如果(时间经过[currentSensorId]
有两种可能性:
int SENSOR_DELAY_FASTEST get sensor data as fast as possible
int SENSOR_DELAY_GAME rate suitable for games
int SENSOR_DELAY_NORMAL rate (default) suitable for screen orientation changes
int SENSOR_DELAY_UI rate suitable for the user interface
而不是自定义值
感谢您找到解决方案。您能上传一些小代码示例吗?您是否在多个设备上试用过?什么时候重置值?你能在使用event.values元素的地方发布代码吗?当设备进入睡眠模式(锁定)时,值似乎开始增加。但是你如何收集这些值呢?您的应用程序在后台运行?好的,您如何存储收集的日期?在数据库中?尝试在影响读取值之前初始化变量。可能它不起作用。需要使用常数SensorManager.SENSOR\u DELAY\u UI或其他。
int SENSOR_DELAY_FASTEST get sensor data as fast as possible
int SENSOR_DELAY_GAME rate suitable for games
int SENSOR_DELAY_NORMAL rate (default) suitable for screen orientation changes
int SENSOR_DELAY_UI rate suitable for the user interface