0

When using the classic TYPE_ACCELEROMETER sensor, you can do something like:

public void onSensorChanged(SensorEvent sensorEvent){
   if (sensorEvent.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
      ax=sensorEvent.values[0];
   }
}

BUT, when using TYPE_LINEAR_ACCELERATION, how is it supposed to provide the info?

I've tried to do things like:

public void onSensorChanged(SensorEvent sensorEvent){
       if (sensorEvent.sensor.getType()==Sensor.TYPE_LINEAR_ACCELERATION){
          ax=sensorEvent.values[0];
       }
    }

But it's not working. I've seen the post Android TYPE_LINEAR_ACCELERATION sensor - what does it show? And also I've looked the official documentation: Sensor and SensorEvent Which are very interesting indeed, but don't talk about how they took the samples. Any Idea?

Community
  • 1
  • 1
ArcDare
  • 3,106
  • 4
  • 27
  • 38

1 Answers1

1

Ok, it's with

sensorEvent.values[0] // for X-Axis
sensorEvent.values[1] // for Y-Axis
sensorEvent.values[2] // for Z-Axis

It was MY fault, because I didn't register the listener properly.

So, In conclussion:

TYPE_LINEAR_ACCELERATION is used like the tradiotional TYPE_ACCELEROMETER

ArcDare
  • 3,106
  • 4
  • 27
  • 38