for my Master thesis i am developing an android application able to collect data from the 3 axes accelerometer of a Samsung Galaxy S5. Cause I want to track human activity I need a sampling rate of approximately 50Hz. I achieve this by setting the sampling rate to SENSOR_DELAY_GAME which works fine. To check the sampling rate, I display the length of the List which contains the acceleromter data on the phones display. Everything works fine when the screen of the phone is on, even if I switch during data collection between different applications. Doing so, I receive about 1500 values in 30 seconds, which means that the accuracy of the sampling rate is suitable for my purposes.
My Problem now is, that when the screen is in timeout, the accelerometer sampling rate decreases to 5Hz and changes up to 50 Hz again when the screen is on. Is there a way to fix the accelerometer sampling rate to 50 Hz?
PS: I would prefer a solution without setting the screen to ON permanently to save battery life.
thanks, Ziegi
Edit: I added the necessary methods which are needed for the accelerometer. The already existing methods onPause(), onStop() and onResume() are not used cause the measurement should only stop if the stop button click event happens.
public void initListeners(){
mSensorManager.registerListener(this,
mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_GAME);
}
public void onSensorChanged(SensorEvent event) {
if (startFlag == true) {
switch(event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
// copy new accelerometer data into accel array
// then calculate new orientation
System.arraycopy(event.values, 0, accel, 0, 3);
calculateAccMagOrientation();
xText.setText("X: " + decimal.format(event.values[0]));
yText.setText("Y: " + decimal.format(event.values[1]));
zText.setText("Z: " + decimal.format(event.values[2]));
xValue.add(event.values[0]);
yValue.add(event.values[1]);
zValue.add(event.values[2]);
try {
xSize.setText(String.valueOf(xValue.size()));} catch(Exception e) {
Toast.makeText(getBaseContext(), "Fehler bei Add to List", Toast.LENGTH_SHORT).show();
}
break;
}
}
}