12

Is there any standard broadcast intent that I can register a BroadcastReceiver for that gets triggered whenever a contact is added or changed? I've been looking through the docs for a while now but haven't found anything. Maybe it's hidden somewhere deep and one of you guys knows where.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Felix
  • 88,392
  • 43
  • 149
  • 167

1 Answers1

6

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.

Felix
  • 88,392
  • 43
  • 149
  • 167
  • 2
    Are you sure that this is impossible? I wanted to be notified of a contact being added -- what are you doing? When are you checking to see if something is dirty? – Aymon Fournier Sep 23 '11 at 15:03
  • 2
    Whenever the sync service is started. The OS *might* start your service automatically after adding a contact, but that's not guaranteed. I suppose you **could** register a content observer (see `ContentResolver.registerContentObserver`), but I think that would require you to have a `Service` running at all times when the device is awake (please stop it when the device goes to sleep). – Felix Sep 23 '11 at 15:35
  • 2
    @Felix I cannot understand one thing, suppose i update/delete a contact from the native app and the relevant flag gets set, now how can i be sure that when my sync adapter runs, the flags were not reset by the google sync adapter etc. ? I know a bit about content providers and sync adapters but cannot figure this thing out. Please Help! – Sarthak Mittal Aug 20 '16 at 15:12