18

I've found that when I start up my game the compass is often out of whack. Objects will fly around and not be where they're supposed to be. But, if I move the phone in a figure eight (or just wave it round in random directions) everything snaps into place within perhaps half a minute.

Does the hardware know when the compass is not calibrated? Would it be possible for me to detect this and pop up a message telling the user "Your android's compass needs to be calibrated. Please move the phone around in a horizontal figure eight motion until this message goes away."

HappyEngineer
  • 4,017
  • 9
  • 46
  • 60

1 Answers1

29

In SensorEventListener there is a function onAccuracyChanged(Sensor sensor, int accuracy) in which you can check the accuracy of the device's magnetometer. There are 4 levels of accuracy (from class SensorManager):

SENSOR_STATUS_ACCURACY_HIGH = 3
SENSOR_STATUS_ACCURACY_MEDIUM = 2
SENSOR_STATUS_ACCURACY_LOW = 1
SENSOR_STATUS_UNRELIABLE = 0
Dani
  • 3,744
  • 4
  • 27
  • 35
Matt K
  • 6,620
  • 3
  • 38
  • 60