0

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).

  1. I am using Attributes with the BroadcastReceiver class (see below) instead of doing the equivalent in AndroidManifest.xml.
  2. SmsRetriever object is initialized in MainActivity Create() method and activated as var smsRetriever = SmsRetriever.GetClient(this.ApplicationContext); and smsRetriever.StartSmsRetriever();

  3. 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.

  4. 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;
        }
    }
user2921851
  • 990
  • 12
  • 26

1 Answers1

0

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.

AgentP
  • 6,261
  • 2
  • 31
  • 52
  • It is clear to me that SMS Retriever message, in a way, is just like a normal message. But I am assuming that the SMS Retriever API intelligence is used to suppress the SMS message going to Messages app. Perhaps I am making a wrong assumption. If you wish to verify the user silently, isn't the message going to Messages app create some discomfort to the user? If the SMS showing up in Messages app is the default case, is there a way to suppress this programmatically? Cannot think of any way obvious. – user2921851 Jun 14 '20 at 15:11
  • 1
    So far, I don't think that causes discomfort to the user. IMO discomfort comes if I have to go to the messaging app then see code and come back to my app and enter it to an edit text manually and then hit on a button to verify it. But what I can say is the thing you are thinking can be implemented in future but currently that's not what it is built for – AgentP Jun 14 '20 at 15:15
  • I agree with you - going back and forth between verifying app and the Messages app with an error-prone text transfer is far more discomforting indeed. I just assumed that the SMS Retriever App made the whole process totally hidden from the user. I just assumed that the BroadcastReceiver is made to sit between Messages app and the host app (which is the most ideal scenario to suppress the SMS message as this could be easily done by Android OS). – user2921851 Jun 14 '20 at 15:33