2

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));
adam.baker
  • 1,447
  • 1
  • 14
  • 30
  • One thing I forgot to mention is that my code for sending and receiving an SMS is just in a subclass of Object -- not an Android class. I can't see why this should make a difference, though. – adam.baker Sep 01 '12 at 07:41
  • The problem is that _getResultCode()_ returns `RESULT_OK` ***even if the message has not been delivered***. See the question about false positives: http://stackoverflow.com/questions/33174463/android-sms-delivery-notification-on-failure-false-positive – 18446744073709551615 Nov 02 '15 at 11:02

1 Answers1

3

I'm a big idiot:

// Field descriptor #14 I
public static final int RESULT_OK = -1;
adam.baker
  • 1,447
  • 1
  • 14
  • 30