Dilip
Dilip

Reputation: 2311

Detect New contact addition in contactList

I have to execute a peace of code on new contact found,So I'm using service to check whether new contact found in the ContactList.My question is-How can we get new contact added in ContactList?

Upvotes: 1

Views: 671

Answers (1)

Sunil Kumar Sahoo
Sunil Kumar Sahoo

Reputation: 53657

Step-1 Create your own content observer and register it to detect any type of contact change

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

Step-2 Write your own logic to detect contact addition if new contact id is added.

Example: Re-query a cursor to the Contacts table each time the ContentObserver changes and maintain the highest known CONTACT_ID value. The newly added contact will have the id which you have stored before

Upvotes: 1

Related Questions