In how to retrieve the list of contacts in android I see code that allows you to read contacts using either ContactsContract.CommonDataKinds.Phone.CONTENT_URI or ContactsContract.Contacts.CONTENT_URI.
What is the difference between them?
When can they be different?
Use ContactsContract.Contacts to query just Contacts and ContactsContract.CommonDataKinds.Phone can be used to query for details like Phone Numbers if you have the ID of a contact.
Be sure to add .CONTENT_URI at the end of the Constant and check the documentation for more information.
Related
I've got an app in the market which stores details against contacts by using a contact picker. When I've returned from the contact picker I had been using the following to obtain the contact:
cursor.getColumnIndex(ContactsContract.Contacts._ID)
I've found that using this is ok until somebody flashes a new rom or gets a new phone and then all the ID's have changed.
I've looked at the android documentation and I've seen references to using ContactsContract.Contacts.LOOKUP_KEY, but the description confuses me "An opaque value that contains hints on how to find the contact if its row id changed as a result of a sync or aggregation."
So what should I be using to store the contact ID?
Lookup Key is the correct reference for contacts.
Contacts Provider / Contacts:
The ContactsContract.Contacts table also has the column LOOKUP_KEY
that is a "permanent" link to the contact row. Because the Contacts
Provider maintains contacts automatically, it may change a contact
row's _ID value in response to an aggregation or sync. Even If this
happens, the content URI CONTENT_LOOKUP_URI combined with contact's
LOOKUP_KEY will still point to the contact row, so you can use
LOOKUP_KEY to maintain links to "favorite" contacts, and so forth.
This column has its own format that is unrelated to the format of the
_ID column.
I have inserted few contacts in through the android emulator.
I wanted to fetch the names, number,emails,etc. for each contact.
I understood that for fetching contact number we need to refer to
ContactsContract.CommonDataKinds.Phone.CONTENT_URI
instead of
ContactsContract.Contacts.CONTENT_URI
My question is how do i link both the query results so that i can aggregate a single contact and its attributes together ? It seems that only ContactsContract.Data.DISPLAY_NAME is common in both the results and the only attribute which can fetched in both the URI's without specifying in the query's projection.
Can anyone guide me ?
Thanks,
Adithya.
try these links:
How to call Android contacts list?
How to get contacts from native phonebook in android
How to obtain all details of a contact in Android
How to get the first name and last name from Android contacts?
How to import contacts from phonebook to our application
Android contacts extraction
How to get all android contacts but without those which are on SIM
Use select from ContactsContract.Data.CONTENT_URI and group results by LOOKUP_KEY. You'll receive a single cursor with phones, emails, etc., grouped by contact.
In onactivityresult we r getting cursor to the contact database to access various fields of contact database we have ContactsContract.PhoneLookup through which we can get index various db columns and then acccess them.
I have table with contacts identified by LOOKUP_KEY and I need JOIN it with system contact data to get real name and photo. Is possible do this? Or I must read contact data for every contact item CursorAdapter and get required information about contact?
This question is related to:
https://stackoverflow.com/questions/7222297/custom-contacts-view-join-or-combine-contactscontract-with-sqlite-table.
But it's without reply.
Maybe a CursorJoiner would do the trick?
The only way to do that is going to be to read the data through the Content Provider, and put it in your own database. Afterwards you can perform JOIN queries with the data.
i am using contacts contract to take the phone number and name from the phone contacts... how can i take the value(the name and number) of a particular contacts into a variable.....i tried a lot but i was only able to display "DISPLAY_NAME and DATA_1".....
You can take a look at the tutorial at http://www.app-solut.com/blog/2011/03/working-with-the-contactscontract-to-query-contacts-in-android/ which covers how to query all contacts and basic information like the name or phone number for these contacts.
Add a type of contact (RawContact), sometimes they are combined with telephone contacts LOOKUP_KEY. It turns out that some contacts entries contain two RawContact'a one integrated phone, one of mine. The question is how to find out whether there is a Contacts RawContract my type? Or learn to RawContacts to which he refers Contacts?
Match the "_id" of the contact to the "contact_id" of the raw contact.