ContentObserver for updating contacts manually

I registered the ContentObserver service from the service, and I get the onchange() function when there is an update in the phone, for example, when I call or update a contact. But I want the onchange() function to onchange() called only when an add, update or delete occurs. But I do not want an incoming or outgoing call to be called. So can someone tell me which URI I can register with ContentObserver ? My code is here

 getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true,new Contact_change()); 

and the Contact_change.java class is similar to

 public class Contact_change extends ContentObserver{ public Contact_service() { super(null); } @Override public void onChange(boolean selfChange){ Log.i("contact_service","onchange"); Super.onChange(selfChange); } @Override public boolean deliverSelfNotifications() { return true; } } 

Edit:
I have one more problem: after stopping the service, if I change the contact, the onchange() function is also called. So how can I stop this or register a ContentObserver .

+7
source share
2 answers

I used ContactsContract.Contacts.CONTENT_VCARD_URI as mentioned here .

And also you can set a threshold time, for example, mentioned here

It is a bit more efficient.

0
source

To stop receiving notifications from ContentObserver, you must unregister it.

Create an instance of ContentObserver that you can use later to register / unregister.

 Contact_change changeObserver = new Contact_change(); 

Register Observer:

 getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true,changeObserver); 

Unregister observer:

 getContentResolver().unregisterContentObserver(changeObserver); 
0
source

All Articles