接收联系人更改(添加、删除和更改)

发布于 2024-12-20 02:17:11 字数 140 浏览 2 评论 0原文

每个联系人不是都有时间戳吗?

我需要收到联系人更改(添加、删除或更改)的通知。我已经实现了一个 ContentObserver,但是通过这种方法,我只能在联系人发生更改时收到通知,但我不知道哪个联系人已被修改!有什么建议吗?

Isn't there a timestamp for each contact?

I need to be notified by a change (add, delele or change) to a contact. I've implemented a ContentObserver, but trough this method I'm only able to be notified if a change occurs on a contact, but I don't know which contact has been modified! Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

成熟稳重的好男人 2024-12-27 02:17:11

检查 ContactsContract.RawContacts

int DIRTY 

读/写 Flag 表示 VERSION 已更改,该行需要由所属账户同步。只要原始联系人发生更改,该值就会自动设置为“1”,除非 URI 指定了 CALLER_IS_SYNCADAPTER 查询参数。同步适配器应始终提供此查询参数以防止不必要的同步:用户更改服务器上的某些数据,同步适配器更新电话上的联系人(不带 CALLER_IS_SYNCADAPTER 标志)标志,该​​标志设置 DIRTY 标志,从而触发同步将更改带到服务器。

同步适配器使用此列在修改联系人时启动联系人同步。
检查一下你是否从中得到了什么。

check ContactsContract.RawContacts
Column

int DIRTY 

read/write Flag indicating that VERSION has changed, and this row needs to be synchronized by its owning account. The value is set to "1" automatically whenever the raw contact changes, unless the URI has the CALLER_IS_SYNCADAPTER query parameter specified. The sync adapter should always supply this query parameter to prevent unnecessary synchronization: user changes some data on the server, the sync adapter updates the contact on the phone (without the CALLER_IS_SYNCADAPTER flag) flag, which sets the DIRTY flag, which triggers a sync to bring the changes to the server.

This column is used by sync adapters to start sync for a contact when contact is modified.
Check if you get anything from this.

泪之魂 2024-12-27 02:17:11

我不得不做类似的事情。我所做的是根据时间戳进行同步。我使用字段跟踪更新联系人的最新时间:

ContactsContract.Contacts.CONTACT_LAST_UPDATED_TIMESTAMP

然后我继续进行同步操作,每次将我的成员变量更新为最新同步时间。同步完成后,将显示上次联系人同步时间。

当更改观察者注册某些内容时,我会查询内容提供程序以获取此时间之后受影响的所有行。然后我迭代游标并处理每一行。

I had to do something similar. What I did was to sync on basis of timestamp. I keep track of the latest time at which a contact was updated using the field :

ContactsContract.Contacts.CONTACT_LAST_UPDATED_TIMESTAMP

And then I proceed with my sync operation and every time updating my member variable to latest sync time. When sync is complete, this has the last contact sync time.

When the change observers register something, I query content provider for all the rows impacted after this time. And then I iterate over the cursor and process each row.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文