0

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.

dririan
  • 305
  • 1
  • 8
  • Is the message over 160 chars? Are there any unicode characters in the message? Some cdma networks don't like unicode, try converting to ASCII. Also, if it's a sprint phone with an integrated google voice number, there could possibly be strange issues there depending on phone/gv settings – Drake Clarris Jul 30 '12 at 18:44
  • The message is of variable length (but should never contain Unicode), but for testing I replaced it with a static four character string (`test`), and the same thing happened. It is a Sprint phone, but without GV integration. I had the GV app installed, but I also tried uninstalling it and rebooting without any effect. – dririan Jul 30 '12 at 18:47
  • Make sure you are importing `android.telephony.SmsManager` not `android.telephony.gsm.SmsManager` – Salil Pandit Jul 30 '12 at 18:48
  • I do indeed `import android.telephony.SmsManager;`. I target Jelly Bean, so I should get deprecation warnings, but I checked myself just in case. – dririan Jul 30 '12 at 18:53
  • Have you tried on different days? My Sprint phone will sometimes hold messages for a day or two before getting them all at once... – Drake Clarris Jul 30 '12 at 18:59
  • I have not, I just noticed this problem last night. To be honest, I'm only so eager to get this resolved quickly because I already have my app on Google Play, and I tested the latest Play release of my app, and it has the same problem on my phone. I'll give it a few days and see if I get spammed with a few dozen messages though. – dririan Jul 30 '12 at 19:02
  • As I wrote in my answer, you should use a pending intent and check the returned result. It could be some network problem or limitation of which you have no knowledge unless you check the result of sending the sms. – wojciii Jul 31 '12 at 15:45

1 Answers1

1

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.

wojciii
  • 4,253
  • 1
  • 30
  • 39
  • I haven't used `sentIntent` because my app won't work without receiving a text anyway, so the radio can't be off, but even if the message doesn't get sent, it doesn't change anything. My app works by taking action when you receive a text message with certain content, and the reply is purely advisory. At the moment, it just replies with a confirmation that the action requested was taken. But thanks, I'll try that out when I get a chance today. – dririan Jul 31 '12 at 16:43
  • I added `sentIntent`, and added a `Log.d` statement to log the results. About 30 seconds after the SMS is sent, it returns `RESULT_ERROR_GENERIC_FAILURE` with an `errorCode` of -1. Thanks! I tried looking, but I couldn't find any good reference; where can I find what `errorCode` -1 means on CDMA devices? – dririan Jul 31 '12 at 17:26
  • I suspect that this is just some generic error code from the modem. :( Try looking at the output of "adb logcat -b radio" when you send the sms. Maybe it will tell you what at-commands are being used and what the result are. Maybe you get some useful info. – wojciii Jul 31 '12 at 18:54
  • Yikes, that's a lot of logs. I don't see any AT commands, though. I see `D/RILC ( 70): [0444]> CDMA_SEND_SMS (uTeleserviceID=4098, bIsServicePresent=0, uServicecategory=0, sAddress.digit_mode=0, Address.Number_mode=0, sAddress.number_type=0, )`, followed by `D/RILC ( 70): [0445]> CDMA_SMS_ACKNOWLEDGE (uErrorClass=0, uTLStatus=0,)`, and finally `D/RILC ( 70): [0444]< CDMA_SEND_SMS {36,(null),-1} fails by E_GENERIC_FAILURE D/RILJ ( 260): [0444]< RIL_REQUEST_CDMA_SEND_SMS error: com.android.internal.telephony.CommandException: GENERIC_FAILURE`. I don't see anything there. :( – dririan Jul 31 '12 at 19:19
  • What happens in the log when you manually send an SMS - does it work? If you compare the new log to the one you just captured - are there any settings which look like they could be wrong when your application sends the SMS? – wojciii Jul 31 '12 at 19:39
  • I assume you're talking about from the stock Messaging app. I see `D/RILC ( 70): [0468]< CDMA_SEND_SMS {38,(null),-1}`, followed by `D/RILJ ( 260): [0468]< RIL_REQUEST_CDMA_SEND_SMS { messageRef = 38, errorCode = -1, ackPdu = null}`, then it broadcasting a PendingIntent, with `SMS send complete. Broadcasting intent:` and an instance of PendingIntent. Judging by the `RIL_REQUEST` bit, the `messageRef` when my app sends it is 36, but when I do it from Messaging, it's 38. That's the only difference I see, and I don't know if that's a random number or not. Doing it manually is much less spammy. – dririan Jul 31 '12 at 20:00
  • Oddly enough, I semi-isolated the problem. For some reason, it only happened when I texted my phone using (and it sent a reply to) my Google Voice number. As I said, I uninstalled the Google Voice app, so my phone and Google Voice weren't linked, but as soon as a tried from a "real" phone number it worked fine. I'm accepting your answer, as you helped with the troubleshooting. Thanks! – dririan Aug 01 '12 at 05:17