Androd-Intent operation ContentProvider obtains the phone number

Source: Internet
Author: User

The Code is as follows:

Import android. app. activity; import android. content. contentUris; import android. content. intent; import android. database. cursor; import android.net. uri; import android. OS. bundle; import android. provider. contactsContract; import android. widget. toast; public class MyIntentContentDemo extends Activity {private static final int PICK_CONTACT_SUBACTIVITY = 1; // define the operation tag @ Overridepublic void onCreate (Bundle savedInst AnceState) {super. onCreate (savedInstanceState); super. setContentView (R. layout. main); Uri uri = Uri. parse ("content: // contacts/people"); // connect URIIntent intent = new Intent (Intent. ACTION_PICK, uri); // specifies Intentsuper. startActivityForResult (intent, PICK_CONTACT_SUBACTIVITY); // call Intent} @ Overrideprotected void onActivityResult (int requestCode, int resultCode, Intent data) {switch (requestCode) {case PICK_CO NTACT_SUBACTIVITY: // receives the returned data Uri ret = data. getData (); // UriString phoneSelection = ContactsContract. CommonDataKinds. Phone. CONTACT_ID + "=? "; // Set the query condition String [] phoneSelectionArgs = {String. valueOf (ContentUris. parseId (ret)}; // query parameter Cursor c = super. managedQuery (ContactsContract. commonDataKinds. phone. CONTENT_URI, null, phoneSelection, phoneSelectionArgs, null); // query all mobile phone numbers StringBuffer buf = new StringBuffer (); // receives all phone buckets. append ("phone number:"); for (c. moveToFirst ();! C. isAfterLast (); c. moveToNext () {// cyclically retrieve the data buf. append (c. getString (c. getColumnIndex (ContactsContract. commonDataKinds. phone. NUMBER ))). append (","); // retrieve the phone number} Toast. makeText (this, buf, Toast. LENGTH_LONG ). show (); // display information }}}

Required permissions:


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.