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 ow开发者_运维技巧n list activity that works properly where the Google intent does not.
NOTE: Must work on Android 1.5 - ContactsContract does not
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.
You need to use the ContactsContract provider to read the data from database.
See this link for details on how to use ContactsContract.
HTH !
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.
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));
}
精彩评论