问题描述
主要是我需要的是取决于默认的Android日历(谷歌)的事件作出反应。
Mainly what I need is to react depending on the events in the default android calendar (Google).
有相当容易查询提供者和获得的事件在任何给定时间,但我的数据必须是一致的所有的时间。我要的是避免查询提供每个x分钟检查是否有新的事件。
It's fairly easy to query the provider and get the events at any given time but my data has to be consistent all the time.What I want is to avoid querying the provider each x min to check for new events.
我找不到任何系统广播的应用程序商店,当新的事件(只有当事件被触发)。只是要清楚,我并不想创建,删除,从我的应用程序等事件,我只是想monitorize他们,我需要建立一个新的事件的时刻,所以我可以重新查询供应商。
I couldn't find any system broadcast for when the app stores the new event (only when the event gets triggered).Just to be clear, I don't want to create, delete, etc events from my app, I just want to monitorize them, I need the moment of the creation of a new event so I can requery the provider.
我知道谷歌有一个(记录很差)日历API,它的经验吗?它是否适合我的需要?
I know Google has a (very poorly documented) Calendar API, any experience with it? Does it suit my needs?
推荐答案
作为这个答案解释类似的问题 ,您可以使用的BroadcastReceiver 从默认的Android日历收到更改事件通过创建一个 BroadcastReciver
有以下意图过滤器:
As explained in this answer to a similar question, you can use a BroadcastReceiver to receive change events from the default Android calendar by creating a BroadcastReciver
with the following intent filter:
<receiver
android:name=".NativeEventChangeReceiver">
<intent-filter>
<action android:name="android.intent.action.PROVIDER_CHANGED"/>
<data android:scheme="content"/>
<data android:host="com.android.calendar"/>
</intent-filter>
</receiver>
请注意,没有信息连同该接收器通过 - 你需要在收到的查询日历API找到发生了什么变化。如果你正在做的,可能需要很长一段时间的操作,你可能要考虑使用一个 WakefulBroadcastReceiver 和 IntentService 以做的时间越长正在运行的进程(如的BroadcastReceiver
取值必须在10秒内完成具体根据的onReceive()文档)。
Note that no information is passed along with this receiver - you'll need to query the calendar API upon receipt of that to find what has changed. If you are doing an operation that may take a long time, you may want to consider using a WakefulBroadcastReceiver and an IntentService to do the longer running process (as BroadcastReceiver
s must complete within 10 seconds as per the onReceive() documentation).
这篇关于听着新的日历事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!