Android:获取当前传感器状态
是的,我可以使用 SensorEventListener 获取传感器更新事件。但这种方法有两个缺点:
1)对于某些传感器,我必须等待状态更新。例如,温度可能会在一分钟后更新!
2)在某些情况下,我可能会得到不正确的读数。例如,手机放在平坦的表面上并且不动。我在侦听器注册后收到第一个方向更新事件。当只有一部分方位矢量发生变化时,其他部分可能为0。并且无法确定它是真正的0度方位角还是只是一个不完整的矢量。如果我稍微移动手机,就会出现正确的非零方位角。
为了解决这个问题,可以创建一个单独的线程来持续监视传感器。一段时间后它肯定会包含真实的值。但我认为对于如此简单的任务来说这是一种开销。
还有其他方法可以获取当前传感器数据吗?
Yes, I can get sensor update events with SensorEventListener. But this approach has 2 drwwbacks:
1) For some sensors I have to wait for the state to update. For example, temperature may update after a minute!
2) In some cases I can get incorrect readings. For example, the phone lies on a flat surface and does not move. I receive first orientation update event after listener registration. When only a part of the orientation vector changes, other parts may be 0. And it is no way to determine, is it a true 0 degree azimuth or just an incomplete vector. If I move the phone a little, the correct non-zero azimuth appears.
To solve this problems it's possible to create a separate thread that constantly monitors sensors. After some time it will certainly contain true values. But I think that it is an overhead for such simple task.
Is it any other way to get current sensor data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,目前的 API 中没有。
Not in the current API, AFAIK, sorry.