I want to get the three values ββof the coordinates of the magnetic field measured by the sensor of my phone. To do this, I get the SensorManager handle using sm=(SensorManager)getApplicationContext().getSystemService(Context.SENSOR_SERVICE) , then I get the sensor with cm=sm.getDefaultSensor(SensorManager.SENSOR_MAGNETIC_FIELD) . Then I register the SensorEventListener to the SensorManager using sm.registerListener(new SensorListener(),cm,SensorManager.SENSOR_DELAY_UI) .
The SensorListener class is a class of my own SensorEventListener interface. It has the OnSensorChanged method, I get the values ββfrom the sensor, and I show them. The problem is that I only get values ββof 1.0 and 0. And they are rarely updated (I set the counter to OnSensorChanged calls to find out how often the update happens). Changing the time to SENSOR_DELAY_NORMAL does not improve anything.
To check if the problem was related to the magnetic sensor, I added, in the same way, a listener to the accelerometer sensor. The result is very confusing: now the magnetic sensor generates updates, but not an accelerometer. And if I delete the accelerometer sensor event receiver, I still get magnetic sensor events that are missing before adding the accelerometer sensor event receiver. (???????????)
Any idea on what's wrong in my code?
source share