SensorManager method crashes program
Posted
by Aidan
on Stack Overflow
See other posts from Stack Overflow
or by Aidan
Published on 2010-06-08T16:35:23Z
Indexed on
2010/06/08
17:32 UTC
Read the original article
Hit count: 185
Hi guys,
When I run the following method my Android application crashes. I can't find the error because I get a "Source Not Found" error. Anyone have any idea's what I'm doing wrong?
public void bearing(){
SensorManager sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
Sensor aSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
Sensor mfSensor = sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
sm.registerListener(myAccelerometerListener, aSensor, SensorManager.SENSOR_DELAY_UI);
sm.registerListener(myMagneticFieldListener, mfSensor, SensorManager.SENSOR_DELAY_UI);
float[] values = new float[3];
float[] R = new float[9];
SensorManager.getRotationMatrix(R, null, accelerometerValues, magneticFieldValues);
SensorManager.getOrientation(R, values);
//Convert from Radians to degrees
values[0] = (float) Math.toDegrees(values[0]);
values[1] = (float) Math.toDegrees(values[1]);
values[2] = (float) Math.toDegrees(values[2]);
}
© Stack Overflow or respective owner