Unable to send text messages on some android phones using SmsManager

My mobile app sometimes sends text messages, everything works fine on most phones, but I am starting to receive emails from some users stating that no messages are coming out. Here is the code I'm using:

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("+12223334444", null, "test sms", null, null);

      

I read somewhere that I have to use PendingIntent, so I tried it like this:

PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_SENT"), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_DELIVERED"), 0);                     
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(number, null, message, sentPI, deliveredPI);   

      

So far, I have received emails from users of Samsung Galaxy S II, Sprint Evo Shift, Samsung Sidekick phones.

Please keep in mind this is not a phone, I tested the app on two of these phones (my friends) and the text message was sent ok

+2


source to share


1 answer


The problem is you don't handle attempts at all. It is possible that SMS will not be able to send different colors. You can listen for these events using dispatched PendingIntent

using something like:

public void onReceive(Context context, Intent intent) {
    if (getResultCode() != Activity.RESULT_OK) {
        // failed to send the sms, see SmsManager.ERROR_<description> for more info on why
    }
}

      



What I suspect is that users have no signal at the moment they send the message, so it fails and never tries again. This also explains why it is not device specific.

+2


source







All Articles