How to get contacts and phone numbers from the Android system

Source: Internet
Author: User

The contact database of the Android system is very complex, not a simple table can be done.

To simply query the user name and phone number, first to query the name, and then enter the name of the phone number, a name may correspond to multiple phone numbers:

    These is the Contacts rows that we'll retrieve. Static final string[] Contacts_summary_projection = new string[]{contactscontract.contacts._id, Con TactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.CONTACT_STATUS, Contactscontract.cont Acts. Contact_presence, ContactsContract.Contacts.PHOTO_ID, ContactsContract.Contacts.LOOKUP_KEY,} Uri BAS        Euri = ContactsContract.Contacts.CONTENT_URI;        Now create and return a cursorloader that would take care of//creating a Cursor for the data being displayed. String select = "((" + ContactsContract.Contacts.DISPLAY_NAME + "notnull) and (" + contactscontract .        Contacts.has_phone_number + "=1" and ("+ ContactsContract.Contacts.DISPLAY_NAME +"! = "))";  return new Cursorloader (ContactActivity.this.getApplicationContext (), BaseUri, Contacts_summary_projection, Select, NULL, COntactsContract.Contacts.DISPLAY_NAME + "COLLATE localized ASC");        list<map<string, string>> list = new arraylist<> ();            while (Data.movetonext ()) {map<string, string> Map = new HashMap ();            String name = data.getstring (Data.getcolumnindex (ContactsContract.Contacts.DISPLAY_NAME));            String ContactId = data.getstring (Data.getcolumnindex (contactscontract.contacts._id));                    Cursor phone = getcontentresolver (). Query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI,                    NULL, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + ContactId,            NULL, NULL); while (Phone.movetonext ()) {String number = phone.getstring (Phone.getcolumnindex (Contactscontract.commonda                TaKinds.Phone.NUMBER));                if (number! = null) {map.put (name, number); }} list.Add (map); }

  

How to get contacts and phone numbers from the Android system

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.