Following most people I guess, I am deriving my SMS handling code from http://mobiforge.com/developing/story/sms-messaging-android. I am trying to catch the broadcasts for sent and delivered messages, with this code (for sent messages):
appContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
Log.i("Debug",
"My embedded receiver: "
+ String.valueOf(getResultCode()));
}
}, new IntentFilter("iam.applications.SmsReceiver.SMS_SENT"));
This always results in getResultCode() returning a value of -1, even when the SMS is successfully sent. I don't know of another way to tell whether my SMS was sent or not.
I have also subclassed BroadcastReceiver to see if that makes any difference, but it does not. -1 is always returned:
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.i("Debug",
"Result code in onReceive: " + String.valueOf(getResultCode()));
}
My creation of the PendingIntent looks like this (snippet from a for-loop for processing parts of long SMS messages):
Intent sentIntent = new Intent(
"iam.applications.SmsReceiver.SMS_SENT");
sentIntent.putExtra(SmsHandler.PHONE_NUMBER, phoneNumber);
sentIntent.putExtra(SmsHandler.MESSAGE, message);
sentPIArray.add(PendingIntent.getBroadcast(appContext,
(int) Calendar.getInstance().getTimeInMillis(), sentIntent,
PendingIntent.FLAG_UPDATE_CURRENT));