听Android的日历变化。 (同步/删除/插入等。) [英] Listen to android calendar changes. (Sync/Delete/Insert etc..)

查看:775
本文介绍了听Android的日历变化。 (同步/删除/插入等。)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经明白,我必须使用内容提供商来让所有的变化,但我也意识到启动 API14 有一个现成的内容提供商的,我可以用它来听,而不是建设自己的自定义的日历。
是否有任何地方,我可以看到这样的例子?
有人可以请张贴这个监听器的核心是什么?

I've understand I have to use Content Provider to get all changes, but I also realized starting API14 there is a ready Content Provider for the calendar which I can use to listen to instead of "building" my own custom one.
Is there anywhere I can see an example of this ?
Can someone please post the core of this listener ?

感谢

推荐答案

首先,你需要这种类型的接收器添加到清单:

First you need to add this type of receiver to the Manifest:

    <receiver android:name="your.package.name.CatchChangesReceiver"
        android:priority="1000" >
        <intent-filter>
            <action android:name="android.intent.action.PROVIDER_CHANGED" />
            <data android:scheme="content" />
            <data android:host="com.android.calendar" />
        </intent-filter>
    </receiver>

然后创建延伸广播接收器一个简单的类:

Then create a simple class which extends broadcast receiver:

public class CatchChangesReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
    // add processing here with some query to content provider
        // in my project I use this selection for getting events:
         final String SELECTION = CalendarContract.Events.CALENDAR_ID + "="
            + calendarId + " AND " + "("
            + CalendarContract.Events.DIRTY + "=" + 1 + " OR "
            + CalendarContract.Events.DELETED + "=" + 1 + ")" + " AND "
            + CalendarContract.Events.DTEND + " > "
            + Calendar.getInstance().getTimeInMillis();
    }
}

这篇关于听Android的日历变化。 (同步/删除/插入等。)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆