I am having an issue related to contacts. I got the phone contacts and stored them in my list object. Here\'s the code for it
Uri uri = ContactsContract.Da
String lastnumber = "0";
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, Constants.PROJECTION, null, null, null);
if (cursor != null) {
try {
final int nameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
final int numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String name, number;
while (cursor.moveToNext()) {
name = cursor.getString(nameIndex);
number = cursor.getString(numberIndex).trim();
number = number.replaceAll("\\s", "");
if (number.equals(lastnumber)) {
} else {
lastnumber = number;
Contact contact = new Contact();
contact.name = name;
contact.phone = number;
mContactList.add(contact);
if (adapter != null)
adapter.notifyDataSetChanged();
System.out.println("ContactFragment.readContact ==>" + name);
}
}
} finally {
cursor.close();
}
}