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