如何在 Android 设备上获取日历事件更新?
我想在 Android 2.2 设备上获取日历事件更新(当添加新事件或删除现有事件时)?
换句话说,我的程序希望收到任何日历事件更改的通知
有人对如何执行此操作有任何想法吗?
I want to get calendar event updates (when a new event is added or an existing event is deleted ) on android 2.2 devices ?
In other words, my program wants to get notifications for any calendar event changes
Anyone has any thoughts regarding how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每当日历更新时,您都可以使用内容观察器获取通知,您必须使用
this.getContentResolver().registerContentObserver(uri, true,observer); 注册第一个观察者;
其中 uri 是日历 uri,如“content://com.android.calendar/events”,观察者是扩展 Content Observer 的类的对象,它覆盖更改方法,当发生更改时调用,
您必须使用通知此观察者
this.getContentResolver().notifyChange(eventsUri, null)
无论您在何处执行更改,例如日历的读取或删除操作
whenever the Calendar update is made,u can get notification by using Content Observer,u have to register first observer using
this.getContentResolver().registerContentObserver(uri, true, observer);
where uri is the the calendar uri like "content://com.android.calendar/events" and observer is the object of the class extending Content Observer which overrides on change method,invoked when the change occurs
you have to notify this observer using
this.getContentResolver().notifyChange(eventsUri, null)
wherever u r performing changes like in read or delete operation of the calendar