当设备从另一部普通电话收到短信时,我的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
发布评论