Broadcast on Contact Add/Change

Broadcast on contact add/change?

Here I go answering my own question (if anyone has a better answer, don't be shy).

There's no broadcast when a contact is added/changed. However, 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, which is pretty much what I was looking for.

Broadcast message when a contact is added or updated

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.

Broadcast Receiver for insertion into contacts

You have to implement an Android Service and register an observer to the list of Contact, you can refer to this question to receive change event on the phonebookContact Change.
After that you can start you application. You can make your service run on device restart by using brodcast receiver for boot.

How to receive Contact changes : Android

Implement a broadcaste Receiver and send Broadcaste in the onChange method of ContentObserver targetting this receiver.. see this for using custom intents and broadcastes..

Native contact change notification

No BroadcastReceiver available for notifying contacts changes. You may need to use ContentObserver to get notified. Lots discussions happened to here on how to receive Contacts change notification via ContentObserver. Try searching for it.

Another way of getting notified, is by using SyncAdapters. Look into here for info http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-2/



Related Topics



Leave a reply



Submit