Here is my code that receives phone numbers and names of the same contact.
public void test111(View view) { ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); if (cur != null && cur.getCount() > 0) { while (cur.moveToNext()) { String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); if (cur.getInt(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) { Cursor pCur = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{id}, null); if (pCur != null) { while (pCur.moveToNext()) { String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); Logger.log(MainActivity.class, "!!!!!!!!! Name : " + name + ", Phone No: " + phoneNo, Logger.ERROR); } } if (pCur != null) { pCur.close(); } } } } } But the problem is that if I need to get an email address if this contact has it, then I need to create a new cursor,
Cursor cur1 = cr.query( ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", new String[]{id}, null); and he, as I understand it, will collect all the available email addresses, but for me they will not be ordered ...
How to make the method return information for each contact if there is a mail, a имя, номер, майл if not, a имя, номер, null ?
Or tell me how it is done correctly?
Or maybe you can somehow get a vCard subscriber card with all its data ... After all, this is how it works when we allow SMS to choose the card of the right person and send it ...
How can you receive such a card programmatically for each subscriber in the phone book and receive all the information on a particular user on this card?