Querying contacts matching a given phone number

  1. SDK Version: 36
  2. Platforms(Android/iOS/web/all): Android

I am writing an app to make it more feasible to view and delete SMS messages on my mobile router because the app that comes with the router is useless for this, the mobile web interface does not allow you to delete messages at all and the desktop interface makes deleting messages clunky and only allows deleting all messages from a contact in one go instead of e.g. one specific message. :man_facepalming:

Using Expo, I already have something that (for the above use case at least) is far more useful than the app/web interface.

Now I would like to query the contacts on my phone to display profile pictures of the senders of the SMS messages. Of course the vast majority of the messages are from my cell phone provider because I don’t give out the number for my router and would not expect family or friends to send messages to it, but still, I’m trying to do this partly out of annoyance with the official app/web interface and partly for fun and learning.

So I have the sender’s phone number and I want to search in my phone’s contacts for one matching that phone number and show the corresponding profile pic and name in my app alongside the SMS message.

This completed feature request says one should be able to search contacts by “name includes ‘xyz’, phone number begins with ‘60’, etc.”

There’s a pointer to the SDK v29 release notes saying that this is now possible, but I don’t see anything in the v29 release notes or the Contacts documentation to show how to search by anything except contactId or name, (and searching by name is apparently not supported on Android anyway).

There’s a tantalising method in the Android source called getContactByPhoneNumber but it’s unfortunately marked as “WIP - Not for SDK 29” and if I understand it correctly it only returns the contact’s displayName, so it would not be possible to get the image because on Android you can’t search by name either.

So it seems the only way to get a profile pic and name for a given phone number would be to fetch the whole list of contacts and filter them manually.

Am I out of luck?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.