2

I have added multiple number under different categories for single user like,enter image description here

If I delete the one of the numbers , I want to detect which number got deleted from contact using ContactsContract content uris

marmor
  • 27,641
  • 11
  • 107
  • 150
Bhoomi Zalavadiya
  • 689
  • 12
  • 26

1 Answers1

1

The ContactsContract APIs can tell you that something changed in the Contacts table (via ContentObserver), but not what exactly.

If you want to detect the change that happened you'll need to keep and maintain a cache copy of all contacts in your app, you don't need to actual data itself, just the hash of each data row for each contact.

Then when you get your onChange called, you can go over all the data rows in the DB and compare them to the hashes you found the last time, and see if any were added/modified/deleted.

marmor
  • 27,641
  • 11
  • 107
  • 150
  • can you elaborate please? – epic Jan 20 '20 at 21:45
  • 1
    you need to store the existing state of each contact, kind of like a clone of the contacts DB within your own app, and then when you observe something changed in one of the contacts, you'll be able to compare the new state with the one you have in your app, and detect which phone was added/removed/edited – marmor Jan 21 '20 at 08:47
  • I understand that and done so, but i am not sure exactly what best to compare. What did you mean about the hashes? Thx in advanced. – epic Jan 21 '20 at 17:56
  • 1
    data about contacts is stored in the Data table where each row represents a specific data item of a single contact, instead of storing the entire row in your local DB, you can calculate a hash-value of that row, and then later calculate the new hash value, and compare it to your previous hash value, this will tell you if the new state of that row had changed or is exactly the same – marmor Jan 22 '20 at 08:20