contact_last_updated_timestamp标志到底返回什么? [英] What exactly contact_last_updated_timestamp flag returns?

查看:127
本文介绍了contact_last_updated_timestamp标志到底返回什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获取在给定时间戳记之后更新的联系人,并且我的代码是

I am fetching the contacts which are updated after given time stamp and my code is

Uri uri = ContactsContract.Contacts.CONTENT_URI;
Cursor cursor = cur = contentResolver.query(uri, null, "contact_last_updated_timestamp > ?", new String[]{timeStamp}, null);

但是光标会返回给定的时间戳后未更新/删除/添加的联系人.
问题是光标从设备的联系人列表中返回了某些联系人.
这意味着查询错误的可能性较小.
我的问题是,为什么光标返回未更新/删除/添加的联系人?
如何获得给定时间戳后更新的联系人列表? (不使用ContentObserver)

But the cursor returns the contacts which are not updated/deleted/added after given timestamp.
The problem is cursor is returns some of the contacts from the device's contacts list.
It means that there is less chances that the query is wrong.
My question is, why cursor is returning the contacts which are not updated/deleted/added ?
How to get the contact list which are updated after given time stamp ? (Without using ContentObserver)

先谢谢您!

推荐答案

在几乎所有设备上,联系人都来自某些云资源,例如Google联系人.

On almost all devices contacts originates from some cloud-source, like Google contacts.

在这种情况下,会有一个SyncAdapter定期运行并遍历所有联系人,以确保它们与他们的云版本同步(同步和同步所有更改).

In which case there's a SyncAdapter that runs periodically and goes over all contacts to make sure they're in sync with the cloud versions of them (sync up and sync down any changes).

大多数SyncAdapter还将修改联系人数据中的某些值(通常是RawContact的SYNC1,SYNC2,SYNC3字段),以存储有关同步过程的一些信息, 例如该联系人最后一次在该时间戳上进行了同步.

Most SyncAdapters will also modify some value in the contacts data (usually SYNC1, SYNC2, SYNC3 fields of the RawContact) to store some information about the sync process, e.g. this contacts had last been synced on that timestamp.

这使CONTACT_LAST_UPDATED_TIMESTAMP字段对于您要尝试执行的操作毫无用处.

This makes the CONTACT_LAST_UPDATED_TIMESTAMP field pretty useless for what you're trying to do.

如果我在设备上运行查询,以检查过去24小时内哪些联系人已更新,则1036中有1003已被修改.

If I run the query on my device, to check which contacts had been updated in the last 24 hours, I get 1003 out of 1036 had been modified.

如果我编写ContentObserver来监听更改的内容,是否会 要求以上方案

If i write ContentObserver to listen for changed caontacts, will it be called for above scenario

一天将被调用很多次,比您期望的更多...

it will be called many many times a day, more then you expect...

我发现的唯一可行的选择是在给定点保留联系人数据库状态的缓存副本,并将其与更新后的状态进行比较.

the only viable option i've found is to keep a cached copy of the state of the contacts DB at a given point and to compare it with the updated state.

您无需保留所有联系人的所有数据,只需保留一些表示联系人状态的hashValue(long或int),因此您需要保留其映射并将其持久保存到本地数据库或数据库中.文件,然后过一段时间,您可以再次创建该地图并将其与以前的地图进行比较,以找出已被删除,添加或修改的联系人. 确保您在计算哈希值时仅考虑诸如姓名,电子邮件,电话之类的有趣字段,以便那些SYNC1,SYNC2频繁更改不会触发错误警报

you don't need to keep all the data for all the contacts, just keep some hashValue (long or int) that represents a contact's state, so you need to keep a map of and persist it to a local database or a file, and after some time, you can create that map again and compare it to the previous map to figure out contacts that had been deleted, added or modified. Make sure you only take into account interesting fields like name, emails, phones when calculating your hash-value, so those SYNC1, SYNC2 frequent changes won't trigger a false-alarm

这篇关于contact_last_updated_timestamp标志到底返回什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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