Search code examples
androidbroadcastreceiverandroid-contentproviderandroid-contactsandroid-broadcast

Broadcast message when a contact is added or updated


What`s the best possible way to know when a contact is added or updated in android? My scenario is that i have to send contacts to server when a contact is added or updated.I want to know when a new contact is added or upated.


Solution

  • There is currently no system broadcast when a new contact is added or changed. The ContactsContract observer should notice such changes but due to a bug it doesn't work.

    There's a workaround, though: when you look up your contacts in the RawContacts table, you have a DIRTY column which is 1 if the contact was changed since the last sync.

    What you need to do is query the column for all values that are 1 and get the corresponding contact. If you wish to do this in the background, you could use a Service, possibly in conjuction with a timer to periodically poll the DIRTY column.