What exactly contact_last_updated_timestamp flag returns?

柔情痞子 提交于 2020-08-10 04:59:18

问题


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);

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)

Thank you in advance!


回答1:


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

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).

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.

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

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.

EDIT:

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.

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



来源:https://stackoverflow.com/questions/57489214/what-exactly-contact-last-updated-timestamp-flag-returns

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