Reputation: 116
I know there are threads about this, and I have been reading them for days.
I think my issue is more specific. I'm trying to get the device rotationaround the y-axis.
If i'm correct, it is called azimuth
When I run the app, it returns 0.0 in logcat after debug logging values[0], values[1], & values[2]
Code:
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
SensorEventListener SEL = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
mSensorManager.getRotationMatrix(rotationMatrix, I, gravity, geomagnetic);
mSensorManager.getOrientation(rotationMatrix, values);
accy = values[0];
System.out.println(accy);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
int rate = SensorManager.SENSOR_DELAY_GAME;
mSensorManager.registerListener(SEL, accelerometer, rate);
mSensorManager.registerListener(SEL, magnetometer, rate);
Logcat:
09-05 17:34:02.622 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.642 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.642 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.662 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.662 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.682 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.682 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.702 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.702 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.722 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.722 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.742 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.742 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.762 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.762 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.782 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.782 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.802 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.802 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
Upvotes: 0
Views: 81
Reputation: 18151
From the code above the parameters gravity
and geomagnetic
in mSensorManager.getRotationMatrix(rotationMatrix, I, gravity, geomagnetic);
are probably zero array
and thus your accy
is always zero
Upvotes: 1