Google SMS检索API不检索SMS消息 [英] Google SMS Retriever API not retreiving SMS messages
问题描述
我正在尝试使用Google的SMS检索器API进行自动SMS验证.我已经按照此处的指示进行操作,但是我的应用未收到任何SMS消息.这是我所做的:
I'm trying to use Google's SMS Retriever API for Automatic SMS Verification. I have followed the directions here but my app is not receiving any SMS messages. Here is what I've done:
我已经在活动中添加了代码以启动SMS检索器客户端:
I've added the code in my activity to start the SMS retriever client:
val client = SmsRetriever.getClient(this)
val retriever = client.startSmsRetriever()
retriever.addOnSuccessListener {
Log.i("loginActivity", "started smsretriever")
}
retriever.addOnFailureListener {
//Problem to start listener
}
从日志中,我看到此操作成功启动.然后,我用此onReceive添加广播接收器:
From the logs, I see this starts successfully. Then I add my broadcast receiver with this onReceive:
override fun onReceive(context: Context, intent: Intent) {
if (SmsRetriever.SMS_RETRIEVED_ACTION == intent.action) {
val extras = intent.extras
val status = extras.get(SmsRetriever.EXTRA_STATUS) as Status
when (status.statusCode) {
CommonStatusCodes.SUCCESS -> {
}
CommonStatusCodes.TIMEOUT -> {
}
}
}
仅在SMS检索器客户端启动5分钟后发送TIMEOUT事件时触发.它永远不会触发SMS消息.
This only triggers when a TIMEOUT event is sent 5 minutes after the SMS retriever client starts. It never triggers for SMS messages.
最后,我已经在清单中注册了接收器:
Finally, I've registered the receiver in the Manifest:
<receiver android:name=".receiver.SMSReceiver" android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.auth.api.phone.SMS_RETRIEVED"/>
</intent-filter>
</receiver>
就短信而言,我正在向自己发送此SMS消息: <#>您的代码是:123456 验证哈希:"
In terms of the text message, I am sending myself this SMS message: "<#> Your code is: 123456 verification hash: "
知道我在做什么错吗?
推荐答案
Maybe your message has wrong construction, please check this link: SMS Retriever API. At the first point, your text message must be begin with <#> or [#]. And at the 4th point, Your text message must be-"End with an 11-character hash string that identifies your app"
我遇到了同样的问题,这就是我的意识,可以通过在开头添加<#>并在末尾添加哈希字符串来解决.
I have the same issue and that points is my awareness, solve by adding <#> in begining and hash string at the end.
这篇关于Google SMS检索API不检索SMS消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!