Getting a result from an activity (by contact example)

Source: Internet
Author: User
Static final int pick_contact_request = 1; // The request codeprivate void pickcontact () {URI contacts = Uri. parse ("content: // contacts"); intent pickcontactintent = new intent (intent. action_pick, contacts); pickcontactintent. settype (phone. content_type); // show user only contacts w/phone numbers startactivityforresult (pickcontactintent, pick_contact_request);} @ overrideprotected void onactivityresult (INT requestcode, int resultcode, intent data) {// check which request it is that we're re responding to If (requestcode = pick_contact_request) {// make sure the request was successful if (resultcode = result_ OK) {// get the URI that points to the selected contact URI contacturi = data. getdata (); // We only need the number column, because there will be only one row in the result string [] projection = {Phone. number, phone. contact_id}; // perform the query on the contact to get the number column // we don't need a selection or sort order (there's only one result for the given URI) // caution: the query () method shocould be called from a separate thread to avoid blocking // your app's UI thread. (For simplicity of the sample, this code doesn't do that .) // consider using cursorloader to perform the query. cursor cursor = getcontentresolver (). query (contacturi, projection, null); cursor. movetofirst (); // retrieve the phone number from the number column int column = cursor. getcolumnindex (phone. number); int column_id = cursor. getcolumnindex (phone. contact_id); string number = cursor. getstring (column); string id = cursor. getstring (column_id); edittext = (edittext) findviewbyid (R. id. edit_message); edittext. settext (number + id );}}}

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.