简体   繁体   English

Awareness API中的TimeFence.inInterval不起作用

[英]TimeFence.inInterval in Awareness API not working

I am using this to set up a time fence: 我用它来设置时间范围:

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

However, the fence is not triggered when the time falls between timeMillis and timeMillis+5L. 但是,当时间落在timeMillis和timeMillis + 5L之间时,不会触发围栏。 My receivers are working properly since all other fences are working as expected. 我的接收器工作正常,因为所有其他围栏都按预期工作。 What can be the problem behind the TimeFence not working? TimeFence背后的问题可能不起作用?

The question does not have sufficient information to pinpoint the potential issue. 该问题没有足够的信息来查明潜在的问题。 From testing, the specific time fence mentioned works as expected. 从测试开始,提到的具体时间栅栏按预期工作。 I can make best-effort at pointing out some common issues. 我可以尽最大努力指出一些常见问题。

  • Looking at the documentation for TimeFence.inInterval , the start and stop time millis are the number of millis since epoch. 查看TimeFence.inInterval的文档,开始和停止时间millis是自纪元以来的millis数。 Please check that the parameters being passed are actually in millis since epoch (as opposed to in a specific timezone or since start of day) 请检查传递的参数实际上是自纪元以来的毫秒数(而不是在特定时区或从一天开始)

  • The interval of the timeFence is 5 milliseconds which is very short. timeFence的间隔是5毫秒,非常短。 As a practical matter, I would set the interval to something that is perceivable, perhaps a few seconds or better still, one minute. 实际上,我会将间隔设置为可感知的东西,可能是几秒或更好,一分钟。

  • On the earlier point, if timeMillis is obtained from System.currentTimeMillis(), then current time plus 5 ms might have already passed by the time the fence is registered with the API. 在前一点,如果timeMillis是从System.currentTimeMillis()获得的,那么当篱笆向API注册时,当前时间加上5毫秒可能已经过了。 Again, this points to using a longer interval in practice. 同样,这指出在实践中使用更长的间隔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM