android - Awareness API 中的 TimeFence.inInterval 不起作用

标签 android google-awareness

我正在使用它来设置时间范围:

ArrayList<AwarenessFence> awarenessFences = new ArrayList<AwarenessFence();
awarenessFences.add(TimeFence.inInterval(timeInMillis, timeInMillis+5L));
AwarenessFence customFence = AwarenessFence.and(awarenessFences);

但是,当时间落在 timeMillis 和 timeMillis+5L 之间时,不会触发围栏。 我的接收器工作正常,因为所有其他围栏都按预期工作。 TimeFence 不工作背后的问题可能是什么?

最佳答案

该问题没有足够的信息来查明潜在问题。从测试来看,提到的特定时间范围按预期工作。我会尽最大努力指出一些常见问题。

  • 查看 TimeFence.inInterval 的文档,开始和停止时间 millis 是自纪元以来的毫秒数。请检查传递的参数实际上是自纪元以来的毫秒数(而不是在特定时区或自一天开始以来)

  • timeFence的间隔是5毫秒,非常短。实际上,我会将间隔设置为可感知的值,可能是几秒或更好,一分钟。

  • 在前面一点,如果 timeMillis 是从 System.currentTimeMillis() 获得的,那么在向 API 注册围栏时,当前时间加上 5 毫秒可能已经过去了。同样,这表明在实践中使用了更长的间隔。

关于android - Awareness API 中的 TimeFence.inInterval 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40875320/

相关文章:

java - 使用 Zip4j : Probably not a zip file or a corrupted zip file 在 Android 中创建 zipFile 时出现异常

android - 在主应用程序和库中使用 Realm

android - 证书固定不适用于 Android 上的 OkHttp

android - Awareness API 需要哪个依赖项?

android - ACL_ACCESS_DENIED 感知 API - Android

Android键盘向下滑动留下黑屏

android - 嵌套 fragment 在方向更改时创建两次

android - 缺少 Google Awareness API v9.6

android - 尝试连接 Google Awareness 服务时收到错误