What exactly contact_last_updated_timestamp flag returns?
Asked Answered
C

1

1

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!

Cornellcornelle answered 14/8, 2019 at 6:30 Comment(0)
H
5

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

Hephzipah answered 14/8, 2019 at 6:46 Comment(4)
marmor,thanks for the answe. If i write ContentObserver to listen for changed caontacts, will it be called for above scenario (Google Contacts) ?Cornellcornelle
@marmor,currently i am having contacts in json object format can u share a link for creating an hash and searching that hashNecklace
@Hephzipah currently i fetched all updated contacts based on last_updated_time_stampNecklace
The multiple calls mean that it is has false positives calls (says it changed, but it didn't). Is there also the opposite, meaning that even though something changed, it doesn't tell you about it? If so, CONTACT_LAST_UPDATED_TIMESTAMP is completely useless for all cases and isn't reliable at all...Orthohydrogen

© 2022 - 2024 — McMap. All rights reserved.