How to get the message sender in SMS User Consent APi in Android?

Viewed 380

I have implemented the message otp in Android following the documentation: https://developers.google.com/identity/sms-retriever/user-consent/request

However, when I receive the SmsRetriever.EXTRA_SMS_MESSAGE (Please go to step 3 in the link), there is no way to get the phone number of the sender.

When you start the SMS User Consent, as follows:

SmsRetriever.getClient(context).startSmsUserConsent(senderPhoneNumber /* or null */)

You can provide the sender number a priori, therefore, the api will filter the messages only for this number. However, I do not like this approach.

What I am trying to discover is how to identify the sender number after receiving the message.

Is there any approach to find the sms sender phone using this Api?

1 Answers

Currently, there is no way to do that in the SMS User Consent APi because even if you pass null in the SmsRetriever.getClient(context).startSmsUserConsent(null) still we can get the sender number in the onReceive method. so, you should listen for incoming message using the broadcast receiver and then put your login inside the onReceive to filter out the messages

Related