How to get rawcontact id with contact id and lookup key

992 Views Asked by At

I am trying to get rawcontacts._ID from contacts provider by using the lookup key and contact id stored in the application.

This function exists that might help me but I am not sure how to construct the rawContactUri

public static Uri getContactLookupUri (ContentResolver resolver, Uri rawContactUri)

Build a CONTENT_LOOKUP_URI style Uri for the parent ContactsContract.Contacts entry of the given ContactsContract.RawContacts entry.

1

There are 1 best solutions below

1
Ashish Agrawal On
    ContentResolver cr = getBaseContext()
                    .getContentResolver();
            Cursor cur = cr
                    .query(ContactsContract.Contacts.CONTENT_URI,
                            null,
                            null,
                            null,
                            null);

            if (cur.getCount() > 0) {

                Log.i("Content provider", "Reading contact  emails");

                while (cur
                        .moveToNext()) {

                    String contactId = cur
                            .getString(cur
                                    .getColumnIndex(ContactsContract.Contacts._ID));
                      }
             }