diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index a120f595..d90e2a00 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -853,7 +853,7 @@ class ThreadActivity : SimpleActivity() { private fun launchPickContactIntent() { Intent(Intent.ACTION_PICK).apply { - type = ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE + type = ContactsContract.Contacts.CONTENT_TYPE launchActivityForResult(this, PICK_CONTACT_INTENT) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/ContactsHelper.kt index 36c9d123..0bfc46db 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/ContactsHelper.kt @@ -20,24 +20,24 @@ class ContactsHelper(val context: Context) { private var displayContactSources = ArrayList() fun getContactFromUri(uri: Uri): Contact? { - val projection = arrayOf(Data.RAW_CONTACT_ID) - val cursor = context.contentResolver.query(uri, projection, null, null, null) + val key = getLookupKeyFromUri(uri) ?: return null + return getContactWithLookupKey(key) + } + + private fun getLookupKeyFromUri(lookupUri: Uri): String? { + val projection = arrayOf(ContactsContract.Contacts.LOOKUP_KEY) + val cursor = context.contentResolver.query(lookupUri, projection, null, null, null) cursor?.use { if (cursor.moveToFirst()) { - val id = cursor.getIntValue(Data.RAW_CONTACT_ID) - return getContactWithId(id) + return cursor.getStringValue(ContactsContract.Contacts.LOOKUP_KEY) } } return null } - private fun getContactWithId(id: Int): Contact? { - if (id == 0) { - return null - } - - val selection = "(${Data.MIMETYPE} = ? OR ${Data.MIMETYPE} = ?) AND ${Data.RAW_CONTACT_ID} = ?" - val selectionArgs = arrayOf(StructuredName.CONTENT_ITEM_TYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE, id.toString()) + private fun getContactWithLookupKey(key: String): Contact? { + val selection = "(${Data.MIMETYPE} = ? OR ${Data.MIMETYPE} = ?) AND ${Data.LOOKUP_KEY} = ?" + val selectionArgs = arrayOf(StructuredName.CONTENT_ITEM_TYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE, key) return parseContactCursor(selection, selectionArgs) }