开发者

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

开发者 https://www.devze.com 2023-03-28 16:24 出处:网络
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 i

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 com开发者_运维百科pass 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."


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号