How can I set query on ContactsContract.CommonDataKinds.Email
and ContactsContract.CommonDataKinds.Phone
in one query and get ID, Name, PhoneNumber and Email .... ?
Like bellow code :
private void getContactList() {
String id = "";
String name = "";
String phoneNo = "";
String mail = "";
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if ((cur != null ? cur.getCount() : 0) > 0) {
while (cur != null && cur.moveToNext()) {
id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
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);
Cursor eCur = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
new String[]{id}, null);
if (pCur != null) {
while (pCur.moveToNext()) {
phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
if (phoneNo != null && !TextUtils.isEmpty(phoneNo)) {
//Log.i("ASDASDASDASDD", "id: " + id);
Log.i("ASDASDASDASDD", "Name: " + name);
Log.i("ASDASDASDASDD", "Phone Number: " + phoneNo);
Log.i("ASDASDASDASDD", "email: ");
} else {
phoneNo = "";
}
}
pCur.close();
} else {
phoneNo = "";
}
if (eCur != null) {
while (eCur.moveToNext()) {
mail = eCur.getString(eCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
if (mail != null && !TextUtils.isEmpty(mail)) {
//Log.i("ASDASDASDASDD", "id: " + id);
Log.i("ASDASDASDASDD", "Name: " + name);
Log.i("ASDASDASDASDD", "Phone Number: " + phoneNo);
Log.i("ASDASDASDASDD", "email: " + mail);
} else {
mail = "";
}
}
eCur.close();
} else {
mail = "";
}
}
//}
}
if (cur != null) {
cur.close();
}
}
I need to have Phone, Name, Id, Email and ... together .