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
Use PhoneNumberUtils.compare(a, b) to filter out duplicated numbers
val contacts = ArrayList()
val uniqueMobilePhones = ArrayList()
while (cursorPhones.moveToNext()) {
val displayName = cursorPhones.getString(cursorPhones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME))
val number = cursorPhones.getString(cursorPhones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))
val convertedNumber = convert(telman, number)
var duplicate = false
uniqueMobilePhones.forEach { addedNumber ->
if (PhoneNumberUtils.compare(addedNumber, number)) {
duplicate = true
}
}
if (!duplicate) {
uniqueMobilePhones.add(number)
contacts.add(MyContact(displayName, number, convertedNumber.replace(Regex("[ -+()]"), "")))
}
}