javaandroidsmscdma

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. My app has the android.permission.SEND_SMS, and works fine on GSM phones. 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. It works on all of the GSM phones I have tried, which are quite a few. logcat shows no errors nor warnings, only D/SMSSMSSMSSMS( 260): TeleService: 4098 each time sendSms is called. Furthermore, I have tried the exact same code in an Activity, and it works perfectly fine.

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. I added a Log.d statement to confirm all three of these. Likewise, PhoneNumberUtils.isWellFormedSmsAddress(destination) returns true.

EDIT: On the advice of @wojci I added a sentIntent and logged the result code. The result code is RESULT_ERROR_GENERIC_FAILURE, with the extra errorCode set to -1. When I try the exact same code from an Activity, however, it works fine with RESULT_OK.


Solution

  • You write that you use the following to send a text: 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?

    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.