开发者

How do I make my Android ContentObserver for detect changed contact detail (added, updated or deleted)?

开发者 https://www.devze.com 2023-04-09 12:10 出处:网络
I can catch the event when contact is modified. But I want to catch that modified contact details like CONTACT_ID, name, etc... Please can you help me to do that. my code is follow.

I can catch the event when contact is modified. But I want to catch that modified contact details like CONTACT_ID, name, etc... Please can you help me to do that. my code is follow.

public class TestContentObserver extends Activity {
    int contactCount = 0;
    final String[] projection = new String[] { RawContacts.CONTACT_ID, RawContacts.DELETED };
    Cursor curval;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        curval = getContentResolver().query(RawContacts.CONTENT_URI, projection, null, null, null);
        contactCount = curval.getCount();

        curval.registerContentObserver(new ContentObserver(new Handler()) {
            @Override
            public void onChange(boolean selfChange) {
                getChangedContactDetails();
            }
            @Override
            public boolean deliverSelfNotifications() {
                return true;
            }
        });

    }



    public void getChangedContactDetails(开发者_开发技巧){
        // how can I catch the affected contact details
    }
}


Have a look at: http://developer.android.com/resources/articles/contacts.html, section "Lookup URI"

when registering your ContentObserver you can just register an URI that points directly to the contact you are interested in. then your observer will only get notified when your interesting contact is modified.

Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
getContentResolver().registerContentObserver(lookupUri, false, new ContentObserver(){});

Lookup key key is unique for each record

0

精彩评论

暂无评论...
验证码 换一张
取 消