SmsMessage.isEmail() 始终返回 false

发布于 2024-12-01 18:49:35 字数 861 浏览 2 评论 0原文

因此,在我的应用程序中,我回复传入的短信,并且我希望能够回复通过电子邮件地址发送的短信,但 isEmail() 始终返回 false,因此 getEmailFrom() 和 getEmailBody() 始终返回 null。这是我的代码:

Bundle bundle = intent.getExtras(); 
    String recMsgString = "";            
    String fromAddress = "";
    String tag = "SMS_RECEIVED";

if (bundle != null)
{
    //---retrieve the SMS message received---
   Object[] pdus = (Object[]) bundle.get("pdus");

    for (int i=0; i<pdus.length; i++){
        SmsMessage recMsg = SmsMessage.createFromPdu((byte[])pdus[i]);

        recMsgString = recMsg.getMessageBody();  

        fromAddress = recMsg.getOriginatingAddress();

        if (recMsg.isEmail()){
           fromAddress = recMsg.getEmailFrom();
           recMsgString = recMsg.getEmailBody();
        }

}

       //do some logging
//code to react to the message
       }
}

任何帮助将不胜感激。

So, in my app, I respond to incoming sms, and I'd like to be able to respond to SMS sent by an email address, but isEmail() always returns false, therefore getEmailFrom() and getEmailBody() always return null. Here's my code:

Bundle bundle = intent.getExtras(); 
    String recMsgString = "";            
    String fromAddress = "";
    String tag = "SMS_RECEIVED";

if (bundle != null)
{
    //---retrieve the SMS message received---
   Object[] pdus = (Object[]) bundle.get("pdus");

    for (int i=0; i<pdus.length; i++){
        SmsMessage recMsg = SmsMessage.createFromPdu((byte[])pdus[i]);

        recMsgString = recMsg.getMessageBody();  

        fromAddress = recMsg.getOriginatingAddress();

        if (recMsg.isEmail()){
           fromAddress = recMsg.getEmailFrom();
           recMsgString = recMsg.getEmailBody();
        }

}

       //do some logging
//code to react to the message
       }
}

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七分※倦醒 2024-12-08 18:49:35

嗯,我从来没有听说过名为 isEmail() 的字符串方法 -​​ 也许我错过了一些东西?

您声明

String recMsgString = "";

然后尝试访问

recMsgString.isEmail()

Which 不存在。另外我注意到您将recMsgString 设置为等于recMsg.getMessageBody()

recMsg.getMessageBody();

我不认为getMessageBody() 函数无论如何都会返回电子邮件。

我认为你的意思是:

SmsMessage recMsg = SmsMessage.createFromPdu((byte[])pdus[i]);

        ...

        if (recMsg.isEmail()){
           fromAddress = recMsg.getEmailFrom();
           recMsgString = recMsg.getEmailBody();
        }

Hrm well I have never heard of a string method called isEmail() - maybe I am missing something?

You declare

String recMsgString = "";

and then try to access

recMsgString.isEmail()

Which does not exist. Also I notice you set recMsgString equal to recMsg.getMessageBody()

recMsg.getMessageBody();

I wouldn't think the getMessageBody() function would return an email anyway.

I think what you meant to do was:

SmsMessage recMsg = SmsMessage.createFromPdu((byte[])pdus[i]);

        ...

        if (recMsg.isEmail()){
           fromAddress = recMsg.getEmailFrom();
           recMsgString = recMsg.getEmailBody();
        }
℉服软 2024-12-08 18:49:35

我有点/有点想通了一些事情,但我不确定它为什么起作用......

所以,在我的应用程序中,而不是检查 isEmail 然后使用 getEmailFromgetEmailBody,我刚刚获得发件人(类似于 14100000011),然后使用 recMsgString.contains(myKeyword)

我的应用程序然后发送一条消息回 14100000011,它会发送到我的电子邮件中。

但我不太确定为什么它会这样。我猜 AT&T 的电子邮件网关只是将邮件发送回我发送的地方。不知道这会起作用。

顺便说一句,有人知道其他运营商的功能吗?

也就是说,如果您从 gmail(或其他电子邮件)向您的电话号码发送电子邮件,如下所示:

AT&T: [电子邮件受保护]
T-Mobile:[电子邮件受保护]
Verizon:[电子邮件受保护]
Sprint:[电子邮件受保护]

然后回复,您是否收到回复消息你的电子邮件?

如果有人愿意对此进行测试,请发表评论,说明您的运营商是谁、您的电子邮件提供商是谁以及测试结果。

I kinda/sorta figured something out, but I'm not sure why it worked...

So, in my app instead of checking isEmail and then using getEmailFrom and getEmailBody, I just got the sender (which is something like 14100000011), and then used recMsgString.contains(myKeyword)

My app then sends a message back to 14100000011 and it delivers to my email.

I'm not really sure why it behaves this way, though. I guess AT&Ts email gateway just delivers back to wherever I sent it from. Didn't know this would work.

On a side note, does anyone know the functioning on any other carrier?

That is, if you send an email from gmail (or another email) to your phone number as such:

AT&T: [email protected]
T-Mobile: [email protected]
Verizon: [email protected]
Sprint: [email protected]

Then reply, do you receive a message back in your email?

If anybody is kind enough to test this, please leave a comment saying who your carrier is and who your email provider is and the results of the test.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文