Looking for a common Contact ID between Telephony.Sms and CallLog.Calls

253 Views Asked by At

Goal: I'm trying to group SMS and calls from same (known) contacts.

  • I read SMS using Telephony.Sms.Inbox.CONTENT_URI and Telephone.Sms.Sent.CONTENT_URI.
  • I read calls using CallLog.Calls.CONTENT_UTI.

I get the contact's ID by following android is CallLog.Calls._ID the same with the contact id?: using Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, phoneNumber).

Now, having this PhoneLookup._ID, I want to list SMS from that contact.

Sadly Telephony.Sms.PERSON does not seem to store the same contact ID.

Question: How could I list SMS from that PhoneLookup._ID or if not possible, how could I achieve what I want: list SMS and calls from the same contact.

PS: Telephony.TextBasedSmsColumns.PERSON seems to refer the the deprecated Contacts.People API...

1

There are 1 best solutions below

0
On BEST ANSWER

Telephony.Sms.PERSON actually matchs ContactsContract.DataColumns.RAW_CONTACT_ID.

So I used:

final Cursor cursor = getContentResolver()
    .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
        projection, selection, null, null);

Reading ContactsContract.DataColumns.RAW_CONTACT_ID.

https://developer.android.com/reference/android/provider/ContactsContract.DataColumns.html#RAW_CONTACT_ID