问题描述
我发现,当我开始了我的游戏罗盘往往是不正常的。对象将飞来飞去,并没有在那里他们应该是。但是,如果我移动电话以8字形(或圆刚摇一摇随机方向)都锁定到位内或许半分钟。
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.
请问硬件知道什么时候罗盘未校准?有没有可能对我来说,检测到并弹出一条消息,告知用户你的Android的指南针需要校准,请在水平八字形运动绕移动电话,直到此消息消失。
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."
推荐答案
在 SensorEventListener
有一个函数 onAccuracyChanged(传感器传感器,INT精度)
在其中您可以查看设备的磁力计的精度。有4级精度(从类的SensorManager
):
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
这篇关于在Android中以编程方式检测到罗盘尚未校准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!