With help of sensorManager I am reading accelerometer reading. Currently slowest setting ie SENSOR_DELEY_NORMAL ,accelerometer reads around 10 times every second. Is there any way by which it can reduce sending reading , may be once every second.
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
Sensor mySensor = sensorEvent.sensor;
if (mySensor.getType() == Sensor.TYPE_ACCELEROMETER) {
x = sensorEvent.values[0];
y = sensorEvent.values[1];
z = sensorEvent.values[2];
rootSquare = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2));
//it reads every second 10 times ie 200 millisecon
}
@Override
protected void onResume() {
super.onResume();
sensorManager.registerListener(this, accelorometer, SensorManager.SENSOR_DELAY_NORMAL);
}
Based on this answer, you could also define your own rate, for example 1000 ms = 1s:
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
Sensor mySensor = sensorEvent.sensor;
if (mySensor.getType() == Sensor.TYPE_ACCELEROMETER) {
x = sensorEvent.values[0];
y = sensorEvent.values[1];
z = sensorEvent.values[2];
rootSquare = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2));
//it reads every second 10 times ie 200 millisecon
}
@Override
protected void onResume() {
super.onResume();
int READINGRATE_ONE_SEC = 1000000;
sensorManager.registerListener(this, accelorometer, READINGRATE_ONE_SEC);
}