确保android不断检索传感器数据 [英] Guarantee that android keeps on retrieving sensor data

本文介绍了确保android不断检索传感器数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个跟踪行程的应用。搜索此问题后,我得出结论,实现此目标(连续跟踪用户的位置)的最佳方法是使用前台服务。在某些情况下效果很好,但在其他情况下(即使关闭了DOZE),我得到了一些时间间隔,其中电话完全处于静止状态,并且我停止获取传感器数据(加速度计或来自融合位置提供程序的位置)。 / p>

当我在Android 9设备上尝试该问题时,这个问题变得更加严重(我想),这是因为它引入了新的限制(手机空闲时没有传感器数据,等等。)。为了解决此问题,或者至少尝试减少其影响,我考虑过实施唤醒锁/作业/警报,仅以1分钟的频率触发,并且什么也不做。

非常感谢您!很长一段时间以来,我一直在为此苦苦挣扎,我不知道该怎么办了。 / p>

解决方案

从您的帖子中


I得到一些时间间隔,在该时间间隔内手机完全静止不动,并且我停止获取传感器数据(加速度计或融合位置提供者的位置)。


如果手机仍然不动,为什么要从跟踪目的中获取任何位置或传感器数据?


I'm developing an app that tracks trips. After searching about this matter, I concluded that the best way to achieve this (continuously track the user's location) is to use a foreground service. In some cases is working quite well, but in some other cases (even with DOZE off), I get some time intervals in which the phone is completely still and I stop getting sensor data (either accelerometer or locations from fused location provider).

This problem got worse when I tried it in an Android 9 device, (i guess) due to the new restrictions introduced by it (no sensor data when the phone is idle, etc.). To solve this issue, or at least try to reduce its effects, I thought about implementing a wakelock/job/alarm just to fire with a 1-minute frequency and do nothing. It might be a really bad idea but I´ve been struggling with this for a long time I dont know what to do anymore.

Thank you very much in advance!

解决方案

From your post

I get some time intervals in which the phone is completely still and I stop getting sensor data (either accelerometer or locations from fused location provider).

If the phone is still, why do you want to get any location or sensor data from tracking purposes?

这篇关于确保android不断检索传感器数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆