通过ContactID来查找联系人信息

首先查找全部的RawContact表,得到一个对应的ContactId,通过这个ContactId查找Contact表,获取该联系人的所有信息,删除的联系人信息应该在RawContact表中不会删除, 只是删除了Contact表里面的数据,所以如果在Contact表中找不到ContactId对应的数据,我就可以判断该联系人被删除了.


        Cursor cursor = getContentResolver().query(

        ContactsContract.RawContacts.CONTENT_URI, null, null, null, null);

        while (cursor.moveToNext()) {
            String rawContactId = cursor.getString(cursor
                    .getColumnIndex(ContactsContract.RawContacts._ID));
            Log.i("RAW_CONTACTS _ID", rawContactId);

            // 得到rawcontact对应的contactId

            String contactId = cursor.getString(cursor
                    .getColumnIndex(ContactsContract.RawContacts.CONTACT_ID));
            Log.i("RAW_CONTACTS CONTACT_ID", contactId);

            // 同步contactId查询contact表,添加一个selector值进行过滤

            Cursor c = getContentResolver().query(
                    ContactsContract.Contacts.CONTENT_URI, null,
                    ContactsContract.Contacts._ID + " =  " + contactId, null,
                    null);
            while (c.moveToNext()) {
                String dn = c
                        .getString(c
                                .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                Log.v("DISPLAY NAME", dn);
            }

            String deleted = cursor.getString(cursor
                    .getColumnIndex(ContactsContract.RawContacts.DELETED));

            Log.i("RAW_CONTACTS DELETED", deleted);
        }
posted on 2012-09-30 00:14  Fra~~kaka  阅读(1046)  评论(0编辑  收藏  举报