0

I have read a little about TYPE_LINEAR_ACCELERATION

private SensorManager mSensorManager;
private Sensor mSensor;
...
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);

but it return 3 values and i dont know how to work with them..

I would like to have it in M/s like next pic enter image description here

I would like get a result like these devices:

enter image description here

angel
  • 4,474
  • 12
  • 57
  • 89

1 Answers1

0

probably it returns acceleration in 3 dimensions. But according to this answer TYPE_LINEAR_ACCELERATION is not the right one to use. You may try to use TYPE_ACCELEROMETER this question is very similar to what u need. Code like below might work to measure the velocity

public void onSensorChanged(SensorEvent se) 
{

    accX = se.values[SensorManager.DATA_X];
    accY = se.values[SensorManager.DATA_Y];
    accZ = se.values[SensorManager.DATA_Z];
    long now = System.currentTimeMillis();
    deltaT = now - lastEvetn;
    lastEvetn = now;

    // calculate velocity in 3D by using 3D acceleration
    Vx = Vx + deltaT * accX;
    Vy = Vy + deltaT * accX;
    Vz = Vz + deltaT * accX;
}
Community
  • 1
  • 1
canbax
  • 3,432
  • 1
  • 27
  • 44
  • Then if a car is moving what is the acceleration? at this moment I am using the location and locationAnt using the formula location.getSpeed()-locationAnt.getspeed()/(location.getTime()-locationAnt.getTime())/1000 – angel Aug 17 '16 at 18:54