Android:获取当前传感器状态

发布于 2024-08-20 22:51:04 字数 354 浏览 4 评论 0原文

是的,我可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柏林苍穹下 2024-08-27 22:51:04

是否有其他方式获取最新信息
传感器数据?

抱歉,目前的 API 中没有。

Is it any other way to get current
sensor data?

Not in the current API, AFAIK, sorry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文