[英]SmsManager.sendTextMessage from a BroadcastReceiver does nothing on CDMA phones
I've got a BroadcastReceiver that handles the android.provider.Telephony.SMS_RECEIVED
action, and sends a text message as a reply in certain cases. 我有一个BroadcastReceiver,它处理
android.provider.Telephony.SMS_RECEIVED
操作,并在某些情况下发送文本消息作为答复。 My app has the android.permission.SEND_SMS
, and works fine on GSM phones. 我的应用程序具有
android.permission.SEND_SMS
,并且在GSM手机上可以正常工作。 However, it doesn't work on the only CDMA phone I have available to me at the moment, and I suspect it only occurs on CDMA phones. 但是,它不适用于我目前仅有的唯一CDMA手机,我怀疑它仅出现在CDMA手机上。 It works on all of the GSM phones I have tried, which are quite a few.
它可以在我尝试过的所有GSM手机上运行,其中有很多。
logcat
shows no errors nor warnings, only D/SMSSMSSMSSMS( 260): TeleService: 4098
each time sendSms
is called. logcat
既不显示错误也不显示警告,仅显示D/SMSSMSSMSSMS( 260): TeleService: 4098
每次调用sendSms
为D/SMSSMSSMSSMS( 260): TeleService: 4098
。 Furthermore, I have tried the exact same code in an Activity, and it works perfectly fine. 此外,我已经在Activity中尝试了完全相同的代码,并且效果很好。
The code I'm using: 我正在使用的代码:
private void sendSms(String destination, String message) {
if(preferencesManager.smsRepliesEnabled()) {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(destination, null, message, null, null);
}
}
preferencesManager.smsRepliesEnabled()
works as expected, and destination
and message
are set properly. preferencesManager.smsRepliesEnabled()
可以正常工作,并且正确设置了destination
和message
。 I added a Log.d
statement to confirm all three of these. 我添加了
Log.d
语句以确认所有这三个条件。 Likewise, PhoneNumberUtils.isWellFormedSmsAddress(destination)
returns true
. 同样,
PhoneNumberUtils.isWellFormedSmsAddress(destination)
返回true
。
EDIT : On the advice of @wojci I added a sentIntent
and logged the result code. 编辑 :根据@wojci的建议,我添加了一个
sentIntent
并记录了结果代码。 The result code is RESULT_ERROR_GENERIC_FAILURE
, with the extra errorCode
set to -1
. 结果代码为
RESULT_ERROR_GENERIC_FAILURE
,额外的errorCode
设置为-1
。 When I try the exact same code from an Activity, however, it works fine with RESULT_OK
. 但是,当我从Activity中尝试完全相同的代码时,它可以与
RESULT_OK
一起RESULT_OK
。
You write that you use the following to send a text: smsManager.sendTextMessage(destination, null, message, null, null); 您写道,您使用以下命令发送文本:smsManager.sendTextMessage(destination,null,message,null,null);
Why are you not using the sentIntent parameter which can tell you if your message was accepted by the network? 为什么不使用sendIntent参数,该参数可以告诉您消息是否被网络接受?
From the documentation: 从文档中:
sentIntent if not NULL this PendingIntent is broadcast when the message is successfully sent, or failed. The result code will be Activity.RESULT_OK for success, or one of these errors:
RESULT_ERROR_GENERIC_FAILURE
RESULT_ERROR_RADIO_OFF
RESULT_ERROR_NULL_PDU
Maybe it can give you some more clues as to why your SMS sending does not work as you expect it to. 也许它可以为您提供一些线索,说明您的SMS发送为何无法按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.