为什么我不能更改加速度计收集的延迟? Android穿

Why can't I change the delay in accelerometer collection? Android wear

在我正在进行的研究项目中,我需要从 android 手表收集加速度计数据(如果有帮助,我正在使用 Asus ZenWatch 3)但我遇到的问题是无论我指定的延迟如何,我总是收到 100 个事件/秒或 100HZ。

我尝试将延迟从 SensorManager.SENSOR_DELAY_NORMAL 更改为 SensorManager.SENSOR_DELAY_GAME、SensorManager.SENSOR_DELAY_UI、SensorManager.SENSOR_DELAY_FASTEST,甚至手动将延迟指定为 20000000 和以微秒为单位的类似值.无论我指定什么延迟,它都会继续以 100HZ 的速率传输。我已经精简了我的代码以简明地展示我所做的事情。我做错了什么?

编辑:在参考中,我一直在使用 https://developer.android.com/guide/topics/sensors/sensors_overview#java 作为该项目的参考。它指出 SENSOR_DELAY_NORMAL 应该是 200,000 毫秒的延迟,尽管根据我的测试这不是我得到的。

public class MainActivity 扩展 WearableActivity 实现 SensorEventListener {

private ExecutorService cachedPool;
private LinkedList<String> xyzValues = new LinkedList<>();
private final String TAG = MainActivity.class.getName(),DELIM = ",";
private SensorManager mSensorManager;
private byte[] bytes;
private Estimator estimator;
private int puffNum = 0,sessionNum = 0,num = 0, BATCH_SIZE = 500, SENSOR_DELAY = 20000000;

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    cachedPool = Executors.newCachedThreadPool(); //part of delivering messages to the phone.

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //Keeps the app working - no screen off

    initSensors();
}
private void initSensors()
{
    try
    {
        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        if(mSensorManager != null) 
        {
            mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        }
    }
    catch(NullPointerException e)
    {
        Log.d(TAG,"FATAL ERROR in initSensors: "+e.getMessage());
    }
}
@Override
public void onSensorChanged(SensorEvent event) //Current sampling rate is 100HZ, taking every 4th point gives 25Hz
{
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        //changes event.timestamp to human readable time.
        String xyzValue = dateFormatted + DELIM + event.values[0] + DELIM + event.values[1] + DELIM + event.values[2] + DELIM + puffNum + DELIM + sessionNum;
        xyzValues.add(xyzValue);
        Log.d(TAG,"xyzValues size:" +xyzValues.size());
        if(xyzValues.size() >= BATCH_SIZE)
        {
            //do the stuff I need such as transmit data
            xyzValues.clear();
        }
    }
}

@Override 
public void onAccuracyChanged(Sensor sensor, int accuracy)
{
    //do something with this
}
@Override
protected void onResume()
{
    super.onResume();
    mSensorManager.registerListener(this, mSensor,SENSOR_DELAY);
    mGoogleApiClient.connect();
}
@Override
protected void onPause()
{
    super.onPause();
    mSensorManager.unregisterListener(this);
    mGoogleApiClient.disconnect();
}

}

延迟值并不总是有效。来自 documentation:

samplingPeriodUs int: ... This is only a hint to the system. Events may be received faster or slower than the specified rate. Usually events are received faster...