I want to get the three coordinates values of the magnetic field measured by the sensor of my phone. For this, I get a handle to the
SensorManager by using
sm=(SensorManager)getApplicationContext().getSystemService(Context.SENSOR_SERVICE), then get the sensor with
cm=sm.getDefaultSensor(SensorManager.SENSOR_MAGNETIC_FIELD). I then register a
SensorEventListener to the
SensorListener is a class of my own implementing the
SensorEventListener interface. In it's
OnSensorChanged method, I get the values from the sensor and I display them. The problem is that I only get the values 1,0 and 0. And they are rarely updated (I have put a counter on the
onSensorChanged calls to see how often the update takes place). Changing the time to
SENSOR_DELAY_NORMAL doesnot improve anything.
To check if the problem was related to the magnetic sensor, I have added, in the same way, a listener to an accelerometer sensor. The result is very confusing : now, the magnetic sensor generates updates, but not the accelerometer one. And if I remove the accelerometer sensor event listener, I still receive the magnetic sensor events which where missing before adding the accelerometer sensor event listener.(???????????)
Any idea about what is wrong in my code?