I'm working on Android 2.0 and am trying to receive a list of all contacts.
Since android.provider.Contacts.People is deprecated, I have to use android.provider.ContactsContract, But I can't find a proper example of how to use it (ex: retrieve a list of all contacts on the phonebook).
Anyone knows where to find such an example?
First, ensure that you have added
to your AndroidManifest.xml file, then you can loop through your phone contacts like this:
Additionally, you can loop through your contacts and simply get the name and phone number like this:
Furthermore, if you need to get things like notes from a contact then you will need to use a different URI, like the following (feel free to use this method):
Notice this time I used not only the contact id but the mime type for the query.
This part wouldn't work for me:
If I use this, though, it does:
Just want to add, when you are retrieving the contacts you might get a lot of "garbage" contacts - for example some email addresses that a user has at some point send an email to, but are not aggregated... If you want only the contacts visible to the user, as in the Androids own contacts application you need to restrict the selection to only IN_VISIBLE_GROUP.