Usually, in Android, we read the accelerometer data in an "Activity", by overriding the OnSensorChanged function.
I am curious how we can do it in a "Service".
Thanks, Vincent
Actually OnSensorChanged(SensorEvent event) is method from interface SensorEventListener.
So if you want to do it in service; you make your new class that extends Service and implements SensorEventListener.
You can do exactly the same in a Service as well.
public class BGHndlr extends Handler implements SensorEventListener {
    public BGHndlr(Looper looper) {
        super(looper);
     }
     @Override
     public void handleMessage(Message msg) {
         oSensorManager.registerListener(this, oAcceleroMeter, SensorManager.SENSOR_DELAY_FASTEST);
     }
    @Override
    public void onSensorChanged(SensorEvent event) {
         // do something
    }
    @Override
     public void onAccuracyChanged(Sensor sensor, int i) {}
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With