I have implemented SMS Retriever on Xamarin Android based on examples such as this and this. Everything works fine as expected EXCEPT the message I am assuming to be intercepted by BroadcastReceiver class (see below) also shows up in the Messages app (where SMS messages show up).
SmsRetriever object is initialized in MainActivity Create() method and activated as var smsRetriever = SmsRetriever.GetClient(this.ApplicationContext);
and smsRetriever.StartSmsRetriever();
My App is using Twilio's Programmable SMS API to send OTP code terminated with an App Hash string on new line, as specified for SMS Retriever API. This works as expected except for the SMS message showing in Messages app.
I also used another phone to send the code, and it works in exactly the same way as Twilio server as above.
Question: Is the message showing up in the Messages app as intended and therefore unavoidable, or am I missing something to have the SMS message suppressed in Messages app?
I am assuming that the SMS Retriever API, having detected the App Hash String, will only forward the SMS message to the BroadcastReceiver and not forward to the Messages app (which at best is pointless to be displayed there).
[BroadcastReceiver(Enabled = true, Exported = true)] [IntentFilter(new[] { SmsRetriever.SmsRetrievedAction })]
public class SmsBroadcastReceiver : BroadcastReceiver
{
public SmsBroadcastReceiver() { }
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action != SmsRetriever.SmsRetrievedAction) return;
var extrasBundleundle = intent.Extras;
if (extrasBundleundle == null) return;
var status = (Statuses)extrasBundleundle.Get(SmsRetriever.ExtraStatus);
switch (status.StatusCode)
{
case CommonStatusCodes.Success:
// Get SMS message contents
var messageContent = (string)extrasBundleundle.Get(SmsRetriever.ExtraSmsMessage);
// Extract one-time code from the message and complete verification
// by sending the code back to your server.
...
break;
case CommonStatusCodes.Timeout:
...
break;
case CommonStatusCodes.NetworkError:
...
break;
case CommonStatusCodes.Interrupted:
...
break;
case CommonStatusCodes.InternalError:
...
break;
default:
...
break;
}
}
The SMS is just like another normal message. So it will show up in the Messages app. SMS retrieval API built just to verify devices.