9

I develop an application which provides some augmented reality features using compass. I found out that sometimes I need to calibrate my compass to make it work well.

How do I know (programatically) that calibration is needed?

I mean I know how to calibrate compass using the 8-pattern figure, but I want to detect that calibration is needed and display some alert to user ("Your compass is not accurate enough, please calibrate your compass sensor.").

Is this possible, please? Thanks!

Berťák
  • 7,143
  • 2
  • 29
  • 38

1 Answers1

7

My solution would be to use the onAccuracyChanged() method of the SensorEventListener interface.

This is how I would do :

//In SensorEventListener interface implementation    
@Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        switch(sensor.getType()){
            case Sensor.TYPE_MAGNETIC_FIELD :
                switch(accuracy) {
                    case SensorManager.SENSOR_STATUS_ACCURACY_LOW :
                        doSomething();
                        break;
                    case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM :
                        doSomethingElse();
                        break;
                    case SensorManager.SENSOR_STATUS_ACCURACY_HIGH :
                        doNothing();
                        break;
                }
                break;
            default:
                break;
        }
    }

You should also look at this answer here : https://stackoverflow.com/a/7877688/7501326

"Typically, if a device is not calibrated, you will see great variations in the azimuth value for small rotations. That is what I would be worried about."

Community
  • 1
  • 1
Kerat
  • 1,284
  • 10
  • 15