简体   繁体   中英

How to get contact that is deleted or updated from device contact list in android

I want to get contact that is either deleted or updated from device contact list.I have used content observer but not getting any details of contact that is being updated or deleted.

So is there any listener for that so we can get contact that is being deleted or updated in device contact list or any action fired from system while deleted or updated contact.

Update :

What actually my application requirment is:

if user delete contact or update contact in device contact list like

在此输入图像描述在此输入图像描述在此输入图像描述

and if user delete that contact then my application require that deleted contact info

As you suggest me to use content observer and lookup uri but using this i am only know that contact is delete but not get any information regarding that delete contact.

So is there any way to get delete contact information.

Thanks in advance

The answer is ContentObserver , it is what you are looking for, You can check this thread for further usage of ContentObserver

Further link for an example of ContentObserver , Observing content

UPDATE:

Loookup URI - If your application needs to maintain references to contacts, you should use lookup keys instead of the traditional row ids. You can acquire a lookup key from the contact itself, it is a column on the ContactsContract.Contacts table.

You can register ContentObserver for a particular Uri that you are interested in using Loookup URI

Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.
                                                   CONTENT_LOOKUP_URI,lookupKey);
getContentResolver().registerContentObserver(lookupUri, false, myObserver);

First u need to register this receiver in your main activity--

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

after that

public class MyCOntentObserver extends ContentObserver {

    public MyCOntentObserver() {
        super(null);
    }

    @Override
    public void onChange(boolean selfChange) {
        super.onChange(selfChange);
        Log.d("onChange1", "~~~~~~" + selfChange);

        //getApplicationContext().startService(new Intent(MainActivity.this, SendContactService.class));
    }

    @Override
    public boolean deliverSelfNotifications() {
        Log.d("deliverSelfNotifications", "~~~~~~fg");
        return true;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM