Android obtains contact information from data

Source: Internet
Author: User

// Jump to the contact page
Private void pickContact (){
// Create an intent to "pick" a contact, as defined by the content provider URI
Intent intent = new Intent (Intent. ACTION_PICK, Contacts. CONTENT_URI );
StartActivityForResult (intent, PICK_CONTACT_REQUEST );
}
 
// The data in the returned Intent is The Uri of the selected contact, indicating The resource location, so that the ContentProvider can query The resource (the URI, using The content: // scheme, for the content to retrieve)
@ Override
Protected void onActivityResult (int requestCode, int resultCode, Intent data ){


If (resultCode = Activity. RESULT_ OK & requestCode = PICK_CONTACT_REQUEST ){

System. out. println ("data. getData ()" + data. getData ());
// The output is content: // com. android. contacts/lookup/0r5-20.c3a525c/5.
Cursor cursor = getContentResolver (). query (data. getData (), new String [] {Contacts. DISPLAY_NAME}, null );
If (cursor. moveToFirst ()){
Int columnIndex = cursor. getColumnIndex (Contacts. DISPLAY_NAME );
String name = cursor. getString (columnIndex );
System. out. println (name );
}
}
}

Related Article

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.