Bounty Award . The prize will be awarded to the response that it receives from the filled Telephony.Sms.Inbox.PERSON
value to the associated Contact
using only the ContractsContact
tables.
I read SMS messages in the standard way in my application:
final String[] projection = {Telephony.Sms.Inbox.BODY, Telephony.Sms.Inbox.ADDRESS, Telephony.Sms.Inbox.READ, Telephony.Sms.Inbox.DATE, Telephony.Sms.Inbox.PERSON}; final Cursor cursor = ctx.getContentResolver().query(Telephony.Sms.Inbox.CONTENT_URI, projection, null, null, Telephony.Sms.Inbox.DEFAULT_SORT_ORDER);
When filling out, the identifier returned from the Telephony.Sms.Inbox.PERSON
index refers to the id of the outdated Contacts.People._ID
and can be used to request additional contact information as follows:
final String[] projection = {Contacts.People.DISPLAY_NAME}; final String[] selectionArgs = {contactId}; final Cursor cursor = ctx.getContentResolver().query(Contacts.People.CONTENT_URI, projection, Contacts.People._ID + " = ?", selectionArgs, null);
Why will the relatively new telephony API use legacy tables instead of ContactsContract ?
Documentation Telephony.Sms.Inbox.PERSON :
Type: INTEGER (link to an element in the content: // contacts / people)
I tried unsuccessfully (but not unsurprisingly?) To find the matching with the identifier in any of the ContactsContract
id fields, so I had to use the outdated APIs to resolve the requests that I needed, execute quickly.
Such requests include searching for messages with a specific contact, for which I only have a name. A contact may have several numbers, which may not be in the correct format, to potentially match the entries of Telephony.Sms.Inbox.ADDRESS
.....
A workaround for using Telephony.Sms.Inbox.ADDRESS
and ContactsContract.PhoneLookup is not the end of the world when moving from number to contact, but I still feel like I have to skip something here ?
Here is the process I use to get posts for "Joe Bloggs".
1) Request the ContactsContract
table to confirm the contact by the name of Joe Bloggs on the device, or get a close match if the contact is really listed as "Joe Blogs ".
2) Using the verified name, I query the legacy Contact.People
table to get all the associated identifiers for the contact as follows:
final String selection = Contacts.People.DISPLAY_NAME + " LIKE ?"; final String[] projection = {Contacts.People.DISPLAY_NAME, Contacts.People._ID}; final String[] selectionArgs = {contactName}; final Cursor cursor = ctx.getContentResolver().query(Contacts.People.CONTENT_URI, projection, selection, selectionArgs, null);
3) Using a list of legacy contact IDs, I request a message table like this:
final String[] referredArgs = new String[contactIdArray.size()]; for (int i = 0; i < contactIdArray.size(); i++) { referredArgs[i] = contactIdArray.get(i); } final String referredSelection = Telephony.Sms.Inbox.PERSON + " IN " + "(" + TextUtils.join(",", referredArgs) + ")"; final String[] projection = {Telephony.Sms.Inbox.BODY, Telephony.Sms.Inbox.ADDRESS, Telephony.Sms.Inbox.READ, Telephony.Sms.Inbox.DATE, Telephony.Sms.Inbox.PERSON}; final Cursor cursor = ctx.getContentResolver().query(Telephony.Sms.Inbox.CONTENT_URI, projection, referredSelection, null, Telephony.Sms.Inbox.DEFAULT_SORT_ORDER);
I hope someone tells me that I am going home here and there is a more obvious solution using modern APIs. I do not consider repeating the entire message table using ContactsContract.PhoneLookup
optimized solution.
Thanks in advance.