Search code examples
androidaccelerometerfrequencyandroid-sensors

Is that possible Accelerometer 1hz update frequency?


is that possible to slow the the accelerometer update frequenzy to 1hz and how?

i've tried it on nexus 7 tab with this: changed the sensorDelay_Normal to 1.000.000 but nothing changed. Thank You!

here is the code:

mAccelerometer.registerListener(listener,mAccelerometer.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.1000000);

Solution

  • This is how I get 1Hz acceleration:

    static int ACCE_FILTER_DATA_MIN_TIME = 1000; // 1000ms
    long lastSaved = System.currentTimeMillis();
    
    @Override
    public void onSensorChanged(SensorEvent event) {
        if ((System.currentTimeMillis() - lastSaved) > ACCE_FILTER_DATA_MIN_TIME) {
            lastSaved = System.currentTimeMillis();
            float x = event.values[0];
            float y = event.values[1];
            float z = event.values[2];
        }
    }