当SMS来自电子邮件时,不会触发android.provider.Telephony.SMS

编程入门 行业动态 更新时间:2024-10-28 10:33:05
当SMS来自电子邮件时,不会触发android.provider.Telephony.SMS_RECEIVED(android.provider.Telephony.SMS_RECEIVED won't fire when SMS comes from an e-mail)

当设备从另一部普通电话收到短信时,我的BroadcastReceiver工作正常,但如果短信是通过运营商的电子邮件网关发送的,如“myphonenumber@mycarrier.com”,那么该设备上的短信通常是作为短信收到的,但android.provider.Telephony.SMS_RECEIVED操作不会触发,我的BroadcatReceiver永远不会收到通知。 有什么我想念的吗?

<receiver android:name=".services.IncomingSmsBroadcastReceiver" > <intent-filter android:priority="2147483647" > <action android:name="android.provider.Telephony.SMS_RECEIVED" > </action> </intent-filter> </receiver>

My BroadcastReceiver works just fine when the device receives an SMS from another regular phone, but if the SMS is sent through the carrier's e-mail gateway like "myphonenumber@mycarrier.com", then the message is received on the device normally as an SMS, but the android.provider.Telephony.SMS_RECEIVED action does not fire and my BroadcatReceiver never gets notified. Is there something I'm missing?

<receiver android:name=".services.IncomingSmsBroadcastReceiver" > <intent-filter android:priority="2147483647" > <action android:name="android.provider.Telephony.SMS_RECEIVED" > </action> </intent-filter> </receiver>

最满意答案

我发现了一些关于运营商如何处理电子邮件的有趣信息,这反过来又导致了我的if语句中的错误行为,从而导致了这个问题中所述的问题。 显然,当手机服务提供商处理您手机的电子邮件时,他们会通过随机短号发送它:例如4043。 在您的BroadcastReceiver ,当您获得SmsMessage ,应始终使用SmsMessage.getDisplayOriginatingAddress()和SmsMessage.getDisplayMessageBody() 。 这些将分别为您提供发送它的电子邮件地址和正确的正文。 与SmsMessage.getOriginatingAddress()和SmsMessage.getMessageBody() ,它将为您提供前面提到的随机数和包含与实际内容混淆的电子邮件地址的正文。

I found something interesting about how carriers handle e-mails, which in turn was causing wrong behavior in my if statements, which in turn caused the problem stated in this question. Apparently, when cell phone service providers handle e-mails to your phone, they send it through a random short number: like 4043 for example. In your BroadcastReceiver, when you get a hold of the SmsMessage, you should always use SmsMessage.getDisplayOriginatingAddress() and SmsMessage.getDisplayMessageBody(). These will give you the e-mail address that sent it and the proper body respectively. Unlike SmsMessage.getOriginatingAddress() and SmsMessage.getMessageBody() which will give you instead the random number mentioned previously and the body containing the e-mail address mixed up with the actual content.

更多推荐

android,收到,SMS,电脑培训,计算机培训,IT培训"/> <meta name="description&qu

本文发布于:2023-07-22 03:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1216695.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电子邮件   SMS   android   Telephony   provider

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!