在 Android 中,我可以以编程方式检测指南针尚未校准吗?
我发现当我启动游戏时,指南针经常失灵。物体会飞来飞去,而不是在它们应该在的地方。但是,如果我以 8 字形移动手机(或者只是以随机方向挥动手机),一切都会在大约半分钟内卡入到位。
硬件是否知道指南针何时未校准?我是否可以检测到这一点并弹出一条消息,告诉用户“您的 Android 指南针需要校准。请以水平 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.
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."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
SensorEventListener
中有一个函数onAccuracyChanged(Sensorsensor, int precision)
,您可以在其中检查设备磁力计的精度。有 4 个精度级别(来自SensorManager
类):In
SensorEventListener
there is a functiononAccuracyChanged(Sensor sensor, int accuracy)
in which you can check the accuracy of the device's magnetometer. There are 4 levels of accuracy (from classSensorManager
):