问题
Im developing a birthday reminder android app. I retrieve all phone contacts and store in sqlite (name, phone, birthdate).
My question is if I can check if user, for example, changes contact name or phone apply this update to my sqlite database.
Do android contacts have any id or something? Thanks!
EDIT: I need to store in a new database table because I have a column 'msg' which sends automatically and SMS if today is someone's birthday.
回答1:
To answer you question, you can see the documentation of the Contact Provider to see what is available.
The ContactsContract.Contacts table also has the column LOOKUP_KEY that is a "permanent" link to the contact row. Because the Contacts Provider maintains contacts automatically, it may change a contact row's _ID value in response to an aggregation or sync. Even If this happens, the content URI CONTENT_LOOKUP_URI combined with contact's LOOKUP_KEY will still point to the contact row, so you can use LOOKUP_KEY to maintain links to "favorite" contacts, and so forth. This column has its own format that is unrelated to the format of the _ID column.
So looking to this LOOKUP_KEYLOOKUP_KEY
An opaque value that contains hints on how to find the contact if its row id changed as a result of a sync or aggregation.
This should be safe to use.
But of course, I would see if it would not be easier to store only the ID and the message you want to send. Let the Contact information where there are, and ask the provider the list of contact who are born today to send the message to them. You don't need to synchronize to distinct database with this solution.
来源:https://stackoverflow.com/questions/43606174/check-if-contact-has-been-changed-on-android-native-contacts-to-update-my-db-sq