I donโt know if you have problems with the accuracy of the compass, but I know what I did when I used
magSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)
I highly recommend using something more like the following.
mySensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE); List<Sensor> mySensors = mySensorManager.getSensorList(Sensor.TYPE_ORIENTATION); if(mySensors.size() > 0){ mySensorManager.registerListener(mySensorEventListener, mySensors.get(0), SensorManager.SENSOR_DELAY_NORMAL); sersorrunning = true; Toast.makeText(this, "Start ORIENTATION Sensor", Toast.LENGTH_LONG).show(); }
I found that when I used a magnetic field sensor rather than an orientation sensor, it worked very well on my phone (Droid Incredible), but all kinds of crazy things on my wifeโs phone (Droid Pro) and my colleagueโs phone (Samsung Galaxy Tab). So you might consider replacing the sensor, just for device compatibility issues. :-)
Jared source share