【问题标题】:How to get the message sender in SMS User Consent APi in Android?如何在 Android 的 SMS User Consent APi 中获取消息发送者?
【发布时间】:2020-05-11 16:30:47
【问题描述】:

我已经按照文档在 Android 中实现了消息 otp:https://developers.google.com/identity/sms-retriever/user-consent/request

但是,当我收到 SmsRetriever.EXTRA_SMS_MESSAGE(请转到链接中的第 3 步)时,无法获取发件人的电话号码。

当您启动短信用户同意书时,如下:

SmsRetriever.getClient(context).startSmsUserConsent(senderPhoneNumber /* or null */)

您可以先验提供发件人号码,因此,api 将仅过滤此号码的消息。但是,我不喜欢这种方法。

我想发现的是收到消息后如何识别发件人号码。

有没有什么方法可以使用这个Api找到短信发件人手机?

【问题讨论】:

    标签: android


    【解决方案1】:

    目前,在 SMS User Consent APi 中无法做到这一点,因为即使您在 SmsRetriever.getClient(context).startSmsUserConsent(null) 中传递 null,我们仍然可以在 onReceive 方法中获取发件人号码。因此,您应该使用广播接收器收听传入的消息,然后将您的登录名放在 onReceive 中以过滤掉消息

    【讨论】:

    • 根据文档,我们可以指定数字,但它对我不起作用?
    猜你喜欢
    • 2015-08-18
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    相关资源
    最近更新 更多