我为Cordova编写了一个插件,用于将加速度计值记录到文件中。我将SENSOR_DELAY_FASTEST模式用于传感器事件侦听器。但是触发的SensorChangedEvent的频率不准确。每0-17毫秒触发一次。
当我在简单的本机android应用程序中实现完全相同的代码时,该事件就会以理想的频率触发(所有事件大约4-5毫秒)。
这是SensorChangedEvent方法的代码:
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
return;
}
// If not running, then just return
if (this.status == SensorTestActivity.STOPPED) {
return;
}
this.setStatus(SensorTestActivity.RUNNING);
this.timestamp = sensorEvent.timestamp;
this.x = sensorEvent.values[0];
this.y = sensorEvent.values[1];
this.z = sensorEvent.values[2];
// this function write record into log file
this.log();
}
我很困惑-Cordova插件和本机应用程序之间的代码执行有什么区别?
谢谢!