The effect diagram looks like this:
First of all, let's say to realize Android jump to the Address Book realization idea:
1. Click to jump to the Address Book interface
2. Get Address Book name and cell phone number
3. Callback display name and cell phone number
1 first jump to the Address Book interface
Uri uri = uri.parse ("Content://contacts/people");
Intent Intent = new Intent (Intent.action_pick, URI);
Startactivityforresult (Intent, 0);
By setting the Address Book URL jump, you can see that we use the callback function to implement
2. Callback function
/* The callback function of the Jump contact list * * *
/@Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
switch (requestcode) {case
0:
if (data==null)
{return
;
}
Processes the returned data, gets the selected contact information
Uri uri=data.getdata ();
String[] Contacts=getphonecontacts (URI);
Et_name.settext (Contacts[0]);
Et_tele.settext (Contacts[1]);
break;
Super.onactivityresult (Requestcode, ResultCode, data);
}
Where the Getphonecontacts (URI) method, because the phone's contact and cell phone number are no longer in the same database, so we need to do separate processing
private string[] Getphonecontacts (Uri uri) {string[] contact=new string[2];
Get Contentresolver object Contentresolver cr = Getcontentresolver ();
Gets the cursor Cursor cursor=cr.query (uri,null,null,null,null) in the beginning of the phone book;
if (cursor!=null) {Cursor.movetofirst ();
Get Contact name int Namefieldcolumnindex=cursor.getcolumnindex (ContactsContract.Contacts.DISPLAY_NAME);
Contact[0]=cursor.getstring (Namefieldcolumnindex);
Get phone number String ContactID = cursor.getstring (Cursor.getcolumnindex (contactscontract.contacts._id));
Cursor phone = cr.query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI, NULL,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + ContactID, NULL, NULL);
if (phone!= null) {Phone.movetofirst ();
CONTACT[1] = phone.getstring (Phone.getcolumnindex (ContactsContract.CommonDataKinds.Phone.NUMBER));
} phone.close ();
Cursor.close ();
else {return null;
return to contact; }
3. Additional Privileges
<!--get Address Book permissions-->
<uses-permission android:name= "Android.permission.READ_CONTACTS"/>
< Uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
The above is a small set to introduce Android jump to the address book to get the user name and mobile phone number of the realization of ideas, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!