Is it possible to get the Mobile Number of SMS that I have received in android? We are trying to authenticate the user's mobile number by sending SMS and getting it from the operator, but the next steps involved authenticating by reading the SMS. The problem that we are facing is, if I send the same message from any other mobile device, there is no way of authenticating the originating SMS number. It blindly reads the SMS.
Google Play services has two APIs you can use to streamline the SMS-based verification process: the SMS Retriever API and the SMS User Consent API. The SMS Retriever API provides a fully automated user experience and should be used when possible.
Getting the sender's mobile number using SMS Retriever API would be a nice option to have in order to avoid the false SMS retrieval. But unfortunately, you cannot get the sender's mobile number for the SMS that you've retrived using this API as of now. This feature may come in future releases.
But if you're already having OTP verification mechanism, there's nothing to worry because...
BONUS
Google has also released a new API called SMS User Consent API, which has the capabilities to auto fill the OTP with One Tap. Luckily, this API also offers sender's mobile number filtering. Meaning, if your SMS provider sends you SMS from a specific mobile number, you can specify it in your code and it'll read SMS received only from that mobile number.
Reference:
SMS Retriever API: https://developers.google.com/identity/sms-retriever/overview
SMS User Consent API: https://developers.google.com/identity/sms-retriever/user-consent/overview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With