Call system contact list
Intent intent = new intent (intent. action_pick, contacts. content_uri );
Startactivityforresult (intent, action_pick );
Get back
Code
1 @ override
2 protected void onactivityresult (INT requestcode, int resultcode, intent ){
3 if (action_pick = requestcode ){
4 If (resultcode = activity. result_ OK ){
5 URI contactdata = intent. getdata ();
6 cursor c = managedquery (contactdata, null );
7 if (C. movetofirst ()){
8 getcontactinfo (intent );
9}
10}
11}
12 Super. onactivityresult (requestcode, resultcode, intent );
13}
Resolve contact information
Code
1 private void getcontactinfo (intent ){
2 cursor = managedquery (intent. getdata (), null );
3 while (cursor. movetonext ()){
4 string contactid = cursor. getstring (cursor. getcolumnindex (contactscontract. Contacts. _ id ));
5 string name = cursor. getstring (cursor. getcolumnindexorthrow (contactscontract. Contacts. display_name ));
6 string phonenumber = NULL, emailaddress = NULL;
7 string hasphone = cursor. getstring (cursor. getcolumnindex (contactscontract. Contacts. has_phone_number ));
8
9 If (hasphone. inclusignorecase ("1 "))
10 hasphone = "true ";
11 else
12 hasphone = "false ";
13
14 if (Boolean. parseboolean (hasphone )){
15 cursor phones = getcontentresolver (). Query (contactscontract. commondatakinds. Phone. content_uri, null,
16 contactscontract. commondatakinds. Phone. contact_id + "=" + contactid, null, null );
17 while (phones. movetonext ()){
18 phonenumber + = phones. getstring (phones. getcolumnindex (contactscontract. commondatakinds. Phone. Number) + ";";
19}
20 phones. Close ();
21}
22
23 txtcontact. settext (name );
24 txtmessage. settext (phonenumber );
25
26 cursor emails = getcontentresolver (). Query (contactscontract. commondatakinds. Email. content_uri, null,
27 contactscontract. commondatakinds. Email. contact_id + "=" + contactid, null, null );
28 while (emails. movetonext ()){
29 emailaddress = emails. getstring (emails. getcolumnindex (contactscontract. commondatakinds. Email. Data ));
30}
31 emails. Close ();
32
33 cursor address = getcontentresolver (). Query (contactscontract. commondatakinds. structuredpostal. content_uri, null,
34 contactscontract. commondatakinds. structuredpostal. contact_id + "=" + contactid, null, null );
35 while (address. movetonext ()){
36 string pobox = address. getstring (address. getcolumnindex (contactscontract. commondatakinds. structuredpostal. pobox ));
37 string street = address. getstring (address. getcolumnindex (contactscontract. commondatakinds. structuredpostal. Street ));
38 string city = address. getstring (address. getcolumnindex (contactscontract. commondatakinds. structuredpostal. City ));
39 string state = address. getstring (address. getcolumnindex (contactscontract. commondatakinds. structuredpostal. region ));
40 string postalcode = address. getstring (address. getcolumnindex (contactscontract. commondatakinds. structuredpostal. postcode ));
41 string Country = address. getstring (address. getcolumnindex (contactscontract. commondatakinds. structuredpostal. Country ));
42 string type = address. getstring (address. getcolumnindex (contactscontract. commondatakinds. structuredpostal. Type ));
43}
44 address. Close ();
45}
46 cursor. Close ();
47}