I am create a demo from receive step from reboot like this.
public class MainActivity extends AppCompatActivity implements SensorEventListener {
private SensorManager sensorManager;
@Override
public void onCreate(Bundle savedInstanceState) {
...
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
}
@Override
protected void onResume() {
super.onResume();
countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_STEP_COUNTER) {
Log.i("TAG","step from reboot" + String.valueOf(event.values[0]));
}
}
}
But when I test on my device (SamSung Galaxy S4), the STEP_COUNTER sometime not work well :(. I figure out it by compare with SHealth
After many many test I found
Almost time, STEP_COUNTER return the step equals SHealth BUT sometime different. Therefore I think SHealth may use another sensor for counting step but I don't know which sensor? I think it is not STEP_DETECTOR because STEP_DETECTOR return very few step when turn off the screen.
Sometime, STEP_COUNTER stop working while SHealth still return the step, for example, I walk about 100 steps => SHealth display 110 and demo app display 100, then I continue walk about 200 steps => SHealth display 305 and demo app display 121 (seem like it stop work)
I also receive the report from many user with different device (with low rating :( ) but I can only reproduce it on my device.
I don't know how to fix this problem. I think STEP_COUNTER is the best sensor for receive step (compare with STEP_DETECTOR)
Any help or suggestion would be great appreciated.