I am developing an app where i need to get contacts & emails from internal phone book..
After some search in google i found the following code for getting phonenum & name.
Main.java
Cursor numcur = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,null, null);
if (numcur != null) {
while (numcur.moveToNext()) {
name = numcur.getString(numcur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
number = numcur.getString(numcur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
phonenumarray.add(number);
displaynamearray.add(name);
}
}
But here to get email id's they are using seperate cursor like as below..
Cursor emailcur = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null,null, null);
if (emailcur != null) {
while (emailcur.moveToNext()) {
email = emailcur.getString(emailcur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA1));
emailarray.add(email);
}
}
As here we are getting values seperately when adding values to listview for contact2 it is displayng contact7 mail id and for contact3 it is showing contat5 mail id as show in below figure.
So, can anyone help me how to get phone num, mail id for same contact..