Android Select contacts Echo

Source: Internet
Author: User

  1. Start the system Select Contact interface

Intent Intent = new Intent (Intent. Action_pick,contactscontract. Contacts. Content_uri);

Startactivityforresult (Intent, 0);

  2. Overriding the Onactivityresult method to get the data

@Override
Public void Onactivityresult (int requestcode, int resultcode, Intent data) {
Super.onactivityresult (Requestcode, ResultCode, data);
if (data!=null) {
switch (requestcode)
{
Case 0:
Uri conatctdata = Data.getdata ();
cursor cursor = managedquery (conatctdata, NULL, NULL, NULL , or null);
if (Cursor.movetofirst ()) {
String contactId = cursor.getstring (Cursor.getcolumnindex (contactscontract.contacts._id));
String names = cursor.getstring (Cursor.getcolumnindexorthrow (ContactsContract.Contacts.DISPLAY_NAME)) ;
Cursor phones = getcontentresolver (). query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI, NULL, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" +contactid, null, NULL);
String phonenum= "";
if (Phones.movetofirst ()) {
phonenum = phones.getstring (Phones.getcolumnindex (ContactsContract.CommonDataKinds.Phone.NUMBER));
}
Name.settext (names);
Phone.settext (phonenum);
if (Build.VERSION.SDK_INT <14) {
phones.close ();
}
}
if (Build.VERSION.SDK_INT <14) {//Do not add Android4.0 above system operation will error
cursor.close ();
}
Break ;
}

}

}

  3. Add Permissions

<uses-permission android:name="Android.permission.READ_CONTACTS"/>




Android Select contacts Echo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.