In my app I read all the contacts from my phone into list view. After clicking on a particular view from the list, I want to read the name, phone and e-mail address. I manage to read the name and phone without a problem. But I can not get the email.
Say I have 2 contacts:
Bill
55-555-555
bil@example.com
Mark
66-666-666
mark@example.com
So the field of the email is called reverse. For Bill I get Mark's email And for Mark I get Bill's email. Other values are correct.
private HashMap<String,String> getContactNames()
{
HashMap<String,String>contact=new HashMap<>();
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
cursor.moveToPosition(pos_listView);
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
phones.moveToPosition(pos_listView);
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Cursor emailcur = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null,null, null);
emailcur.moveToPosition(pos_listView);
String email = emailcur.getString(emailcur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA1));
contact.put("name",name);
contact.put("phoneNumber",phoneNumber);
contact.put("email",email);
cursor.close();
return contact;
}