SmsMessage.isEmail() 始终返回 false
因此,在我的应用程序中,我回复传入的短信,并且我希望能够回复通过电子邮件地址发送的短信,但 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,我从来没有听说过名为 isEmail() 的字符串方法 - 也许我错过了一些东西?
您声明
然后尝试访问
Which 不存在。另外我注意到您将recMsgString 设置为等于recMsg.getMessageBody()
我不认为getMessageBody() 函数无论如何都会返回电子邮件。
我认为你的意思是:
Hrm well I have never heard of a string method called isEmail() - maybe I am missing something?
You declare
and then try to access
Which does not exist. Also I notice you set recMsgString equal to recMsg.getMessageBody()
I wouldn't think the getMessageBody() function would return an email anyway.
I think what you meant to do was:
我有点/有点想通了一些事情,但我不确定它为什么起作用......
所以,在我的应用程序中,而不是检查
isEmail
然后使用getEmailFrom
和getEmailBody
,我刚刚获得发件人(类似于 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 usinggetEmailFrom
andgetEmailBody
, I just got the sender (which is something like 14100000011), and then usedrecMsgString.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.