我已经在Xamarin Android上实现了基于这样和这样的例子的短信检索器。 除了我假设的被BroadcastReceiver类截获的消息(见下文)也显示在Messages应用程序中(SMS消息显示在其中)之外,一切都像预期的那样正常工作。
>
smsRetriever对象在MainActivity Create()方法中初始化,并作为var smsRetriever=smsRetriever.GetClient(This.ApplicationContext);
和smsRetriever.StartSMSRetriever();
激活
我的应用程序正在使用Twilio的可编程SMS API发送OTP代码,在新行上以应用程序哈希字符串终止,这是为SMS检索器API指定的。 除了短信消息显示在Messages App之外,这与预期一样工作。
我还使用了另一部电话发送代码,它的工作方式与上面的Twilio服务器完全相同。
问:消息显示在Messages应用程序中是预期的,因此是不可避免的,还是我错过了一些东西,使SMS消息在Messages应用程序中被抑制?
我假设SMS检索器API在检测到应用程序散列字符串后,只将SMS消息转发给广播接收器,而不转发给消息应用程序(在最好的情况下显示在那里是没有意义的)。
[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;
}
}
短信就像另一条普通的短信。 所以它会显示在消息应用程序中。 SMS检索API建立只是为了验证设备。