Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Android can I programmatically detect that the compass is not yet calibrated?

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."

like image 933
HappyEngineer Avatar asked Aug 17 '11 21:08

HappyEngineer


1 Answers

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
like image 74
Matt K Avatar answered Oct 10 '22 05:10

Matt K