Reputation: 1584
My mobile app occasionally is sending text messages, everything works great on most phones but i am starting to receive emails from some users stating the messages aren't going out. Here is the code i am using:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("+12223334444", null, "test sms", null, null);
I've read somewhere that I should use the PendingIntent, so i tried it as follows:
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 gotten emails from users of Samsung Galaxy S II, Sprint Evo Shift, Samsung Sidekick phones.
Please keep in mind it's not phone specific, i have tested the app on two of these phones (my friends) and the text message was sent normally
Upvotes: 2
Views: 2166
Reputation: 3440
The problem here is that you aren't handling retries at all. It is possible for the SMS to fail to send in a variety of colourful ways. You can listen for these events using the sent 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 happening is that users have no signal at the time you send the message, so it fails and never retries. This would also explain why it isn't device specific.
Upvotes: 3