ACTION_TIME_CHANGED 或 ACTION_DATE_CHANGED,无法使它们工作
所以我正在努力争取一些为我工作的意图, 我在 2 个具体意图上遇到了问题。我搜索了这些组 和网络,似乎找不到更多的信息 该文档给了我。 如果我在中声明这些意图的使用似乎并不重要 清单,或者如果我尝试在代码中注册接收器,我的接收器 从未收到 ACTION_TIME_CHANGED
的操作或 ACTION_DATE_CHANGED
。 据我所知,我应该在我的帐户中收到这些操作 每当用户明确设置时间/日期时广播接收器 转到“设置”--> “日期和时间”
,然后修改时间或 日期 我是否误解了这些行动的目的? 我是否需要声明任何权限才能接收 这些动作? 有人参与过这个行动吗?
是否有一些使用此操作的有用示例,我找不到任何有用的东西,有很多格式更改的示例,但没有实际的 time_date 更改...
提前致谢
So I am in the process of trying to get a few intents to work for me,
and am having problems on 2 specific intents. I searched these groups
and the webs and can 't seem to find any more information than what
the documentation gives me.
It doesn't seem to matter if I declare the use of these intent in the
manifest, or if I try to register a receiver in code, my receiver
never receives the actions for ACTION_TIME_CHANGED
orACTION_DATE_CHANGED
.
As far as I can tell I should be receiving these actions in my
broadcast receiver whenever the user explicitly sets the time/date by
going to "Settings" --> "Date & Time"
and then modifying the time or
date
Am I mis-interpreting what these actions are for?
Are there any permissions that I need to declare in order to receive
these actions?
Does anybody worked with this actions ?
Is there some useful example where this actions are used, I could not find anything useful, there is plenty of examples of format change but not on actual time_date change...
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的,您必须添加
Yes, you must add
你不需要任何许可。
为了收到日期更改的通知,您需要使用这些操作(以及
ACTION_TIMEZONE_CHANGED
)注册到 BroadcastReceiver 。这是我提出的解决方案:
https://stackoverflow.com/a/48782963/878126
You don't need any permission.
In order to be notified of date changes, you need to register to a BroadcastReceiver with those actions (and also
ACTION_TIMEZONE_CHANGED
) .Here's a solution I've made:
https://stackoverflow.com/a/48782963/878126
在您的广播接收器 onReceive 方法中,我假设您有与以下类似的设置?
另一个考虑因素是您是否向 IntentFilter 添加了适当的过滤器,例如......
Inside your broadcast receiver onReceive method I am assuming u have a similar setup to the following?
Another consideration would be did you add the proper filters to your IntentFilter such as...
我用来在日期更改时采取操作的另一种方法。
实际上,当您手动更改手机上的日期时,Intent.ACTION_DATE_CHANGED 仅适用于提前日期的日期,不适用于先前的日期。另外,当您将时间设置为 11:59 并等待它变为 00:00 来为您提供日期更改的广播事件时,它不会为您提供触发器。
因此,我最终制定了自己的逻辑,将日期存储在共享首选项中,然后检查当前日期是在先前存储的日期之后还是之前(使用一些日期处理逻辑),并据此更新我的数据。
An alternative approach which I used to take an action when the date is changed.
Actually, the Intent.ACTION_DATE_CHANGED only works with the date of an advanced date and not with a previous date when you change the date on the phone manually. Also, when you set time to 11:59 and wait for it to become 00:00 to give you the broadcast event of the date change, it doesn't give you the trigger.
So, I ended up making my own logic of storing a date in shared pref and then checking if the current date is after or before previously stored date (with some date processing logic) and updating my data based on that.
除了
之外,请参阅 Android关于 AOSP 错误的 ACTION_DATE_CHANGED 广播:ACTION_TIME_CHANGED
应在时钟设置后触发,并且当时钟滴答作响到第二天时,ACTION_DATE_CHANGED
应该触发,但如果时钟向后设置,ACTION_DATE_CHANGED
不会再次触发,直到时钟赶上正在发生的事情到第二天。In addition to the
<intent-filter>
, see Android ACTION_DATE_CHANGED broadcast about an AOSP bug:ACTION_TIME_CHANGED
should fire when the clock gets set andACTION_DATE_CHANGED
should fire when the clock ticks over to the next day, but if the clock gets set backwards,ACTION_DATE_CHANGED
won't fire again until the clock catches up with what was going to be the next day.Intent.ACTION_DATE_CHANGED
和Intent.ACTION_TIME_CHANGED
仅在用户手动更改时间或日期时触发,系统不会自动触发。恐怕你必须使用
Intent.ACTION_TIME_TICK
,它由系统每分钟触发一次。Intent.ACTION_DATE_CHANGED
andIntent.ACTION_TIME_CHANGED
are triggered only when the user manually changes time or date, and they are not automatically triggered by the system.I'm afraid you have to use
Intent.ACTION_TIME_TICK
, which is triggered by the system exactly each minute.