Cameron McBride
Cameron McBride

Reputation: 6799

Getting a list of all phone contacts?

NOTE: Must work on Android 1.5 - ContactsContract does not

Simple enough question. I need to know the best way to get the same list of contacts that show up when a user presses the Contacts button.

You would think something like this would work:

//For Contacts
Intent pickIntent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
this.startActivityForResult(pickIntent, RESULT);

//For Phones
Intent pickIntent = new Intent(Intent.ACTION_PICK, Phones.CONTENT_URI);
this.startActivityForResult(pickIntent, RESULT);

The problem is that does not include secondary google accounts or Exchange contacts. By secondary accounts, in Android you can add additional gmail accounts to have the mail/contacts synced. The above intent will not list those additional contacts.

I am also told that on the HTC Desire you can add contacts to the phone that do not get synced up to Google. These contacts also do not show up.

So how do I get a real list of contacts so I can create my own list activity that works properly where the Google intent does not.

NOTE: Must work on Android 1.5 - ContactsContract does not

Upvotes: 3

Views: 7229

Answers (4)

calvinmarkes
calvinmarkes

Reputation: 7

Cursor cursor=getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    while ( cursor.moveToNext() ) {
        String name=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

    }

Upvotes: -1

molnarm
molnarm

Reputation: 10031

See here for a detailed description of accessing contacts on Android. It also helps you creating an application that uses ContactsContract if possible but still works on older Android versions.

Upvotes: 3

Vamsi
Vamsi

Reputation: 5993

do refer the question below, How to read contacts on Android 2.0

People class is depreciated from Android 2.0 you have to use ContactsContract class instead.

Upvotes: 0

Karan
Karan

Reputation: 12782

You need to use the ContactsContract provider to read the data from database.

See this link for details on how to use ContactsContract.

HTH !

Upvotes: 3

Related Questions