Listen for new calendar events

守給你的承諾、 提交于 2019-12-03 01:38:46
ianhanniballake

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>

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 BroadcastReceivers must complete within 10 seconds as per the onReceive() documentation).

     <receiver android:name=".MyBroadcastReceiver"  android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.EVENT_REMINDER" />
            <data android:scheme="content"/>
            <data android:host="com.android.calendar"/>
        </intent-filter>
    </receiver>

this will trigger your onReceive(). Set an EVENT in your calendar with a 10 min notification before the event. The trigger will take place ONLY at the notification time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!