public interface Basecolumns
{
public static final String _id = "_id";
public static final String _count = "_count";
}
Protected interface Contactscolumns
{
public static final String display_name = contactnamecolumns.display_name_primary; Names in Contacts
public static final String photo_id = "photo_id";
public static final String photo_file_id = "photo_file_id";
public static final String Photo_uri = "Photo_uri";
public static final String Photo_thumbnail_uri = "Photo_thumb_uri";
public static final String In_visible_group = "In_visible_group";
public static final String is_user_profile = "Is_user_profile";
public static final String Has_phone_number = "Has_phone_number";
public static final String Lookup_key = "LOOKUP";
public static final String Contact_last_updated_timestamp = "Contact_last_updated_timestamp";
}
Protected interface Contactoptionscolumns
{
public static final String times_contacted = "times_contacted";
public static final String last_time_contacted = "last_time_contacted";
public static final String starred = "starred";
public static final String Custom_ringtone = "Custom_ringtone";
public static final String send_to_voicemail = "Send_to_voicemail";
}
Protected interface Contactnamecolumns
{
public static final String Display_name_source = "Display_name_source";
public static final String display_name_primary = "Display_name";
public static final String display_name_alternative = "Display_name_alt";
public static final String Phonetic_name_style = "Phonetic_name_style";
public static final String phonetic_name = "Phonetic_name";
public static final String sort_key_primary = "Sort_key";
public static final String sort_key_alternative = "Sort_key_alt";
}
Protected interface Contactstatuscolumns
{
public static final String contact_presence = "Contact_presence";
public static final String contact_chat_capability = "contact_chat_capability";
public static final String contact_status = "Contact_status";
public static final String Contact_status_timestamp = "Contact_status_ts";
public static final String contact_status_res_package = "Contact_status_res_package";
public static final String Contact_status_label = "Contact_status_label";
public static final String Contact_status_icon = "Contact_status_icon";
}
Traverse all column names and their corresponding values in the Address book:
public class Mainactivity extends Activity {
class people
{
Private String colname;
Private String Colval;
Public String Getcolname () {
return colname;
}
public void Setcolname (String colname) {
This.colname = colname;
}
Public String Getcolval () {
return colval;
}
public void Setcolval (String colval) {
This.colval = Colval;
}
}
Private list<people> peoples=new arraylist<> ();
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Contentresolver Cr=getcontentresolver ();
Cursor cur=cr.query (ContactsContract.Contacts.CONTENT_URI, NULL, NULL, null,null);
while (Cur.movetonext ()) {
string[] ColumnNames = Cur.getcolumnnames ();
for (int i = 0; i < columnnames.length; i++) {
People p=new people ();
P.setcolname (Columnnames[i]);
P.setcolval (Cur.getstring (Cur.getcolumnindex (columnnames[i)));
Peoples.add (P);
}
}
for (int i = 0; i < peoples.size (); i++) {
System.out.println ("list:" + peoples.get (i). Getcolname () + "column value:" +peoples.get (i). Getcolval ());
}
The effect is as follows:
11-06 10:46:54.147:i/system.out (25193): Listed: Send_to_voicemail column value: 0
11-06 10:46:54.147:i/system.out (25193): Listed: organization_note column value: null
11-06 10:46:54.147:i/system.out (25193): Listed: Custom_ringtone column value: null
11-06 10:46:54.147:i/system.out (25193): Listed: name_raw_contact_id column value: 15
11-06 10:46:54.147:i/system.out (25193): Listed: photo_file_id column value: null
11-06 10:46:54.147:i/system.out (25193): Listed: Has_phone_number column value: 1
11-06 10:46:54.147:i/system.out (25193): Listed: Contact_status_label column value: null
11-06 10:46:54.147:i/system.out (25193): List: Display_name column values: Litang (MOM)
11-06 10:46:54.147:i/system.out (25193): Listed: Sort_key_alt column value: Li Li TANG Tang (MA)
11-06 10:46:54.147:i/system.out (25193): Listed: In_visible_group column value: 1
11-06 10:46:54.147:i/system.out (25193): Listed: Starred column value: 0
11-06 10:46:54.147:i/system.out (25193): List: Display_name_alt column values: Litang (MOM)
11-06 10:46:54.147:i/system.out (25193): Listed: Sort_key column value: Li Li TANG Tang (MA)
11-06 10:46:54.147:i/system.out (25193): Listed: contact_presence column value: null
11-06 10:46:54.147:i/system.out (25193): Listed: contact_status_res_package column value: null
11-06 10:46:54.147:i/system.out (25193): Listed: contact_status_ts column value: null
11-06 10:46:54.147:i/system.out (25193): Listed: Sns_type column value: 0
11-06 10:46:54.147:i/system.out (25193): Listed: times_contacted column value: 64
11-06 10:46:54.147:i/system.out (25193): Listed: contact_status column value: null
11-06 10:46:54.147:i/system.out (25193): Listed: phonetic_name column value: null
11-06 10:46:54.147:i/system.out (25193): Listed: Phone_number column value: 15936165107
11-06 10:46:54.147:i/system.out (25193): Listed: Phonetic_name_style column value: 0
11-06 10:46:54.152:i/system.out (25193): Listed: Is_user_profile column value: 0
11-06 10:46:54.152:i/system.out (25193): List: Lookup column value: 930IFLYME-17
11-06 10:46:54.152:i/system.out (25193): Listed: Contact_status_icon column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: last_time_contacted column value: 1403269106387
11-06 10:46:54.152:i/system.out (25193): Listed: _id column value: 16
11-06 10:46:54.152:i/system.out (25193): Listed: Display_name_source column value: 40
11-06 10:46:54.152:i/system.out (25193): Listed: Photo_uri column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: Photo_thumb_uri column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: contact_chat_capability column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: photo_id column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: Send_to_voicemail column value: 0
11-06 10:46:54.152:i/system.out (25193): Listed: organization_note column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: Custom_ringtone column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: name_raw_contact_id column value: 17
11-06 10:46:54.152:i/system.out (25193): Listed: photo_file_id column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: Has_phone_number column value: 1
11-06 10:46:54.152:i/system.out (25193): Listed: Contact_status_label column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: Display_name column value: Liu Kai
11-06 10:46:54.152:i/system.out (25193): Listed: Sort_key_alt column value: Liu Liu Kai Kai
11-06 10:46:54.152:i/system.out (25193): Listed: In_visible_group column value: 1
11-06 10:46:54.152:i/system.out (25193): Listed: Starred column value: 0
11-06 10:46:54.152:i/system.out (25193): Listed: Display_name_alt column value: Liu Kai
11-06 10:46:54.152:i/system.out (25193): Listed: Sort_key column value: Liu Liu Kai Kai
11-06 10:46:54.152:i/system.out (25193): Listed: contact_presence column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: contact_status_res_package column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: contact_status_ts column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: Sns_type column value: 0
11-06 10:46:54.152:i/system.out (25193): Listed: times_contacted column value: 40
11-06 10:46:54.152:i/system.out (25193): Listed: contact_status column value: null
11-06 10:46:54.152:i/system.out (25193): Listed: phonetic_name column value: null
11-06 10:46:54.157:i/system.out (25193): Listed: Phone_number column value: 18736579852
11-06 10:46:54.157:i/system.out (25193): Listed: Phonetic_name_style column value: 0
11-06 10:46:54.157:i/system.out (25193): Listed: Is_user_profile column value: 0
11-06 10:46:54.157:i/system.out (25193): List: Lookup column value: 930iflyme-16
11-06 10:46:54.157:i/system.out (25193): Listed: Contact_status_icon column value: null
11-06 10:46:54.157:i/system.out (25193): Listed: last_time_contacted column value: 1414759606574
11-06 10:46:54.157:i/system.out (25193): Listed: _id column value: 17
11-06 10:46:54.157:i/system.out (25193): Listed: Display_name_source column value: 40
11-06 10:46:54.157:i/system.out (25193): Listed: Photo_uri column value: null
11-06 10:46:54.157:i/system.out (25193): Listed: Photo_thumb_uri column value: null
11-06 10:46:54.157:i/system.out (25193): Listed: contact_chat_capability column value: null
11-06 10:46:54.157:i/system.out (25193): Listed: photo_id column value: null
}
}
Android Contacts Provider