15

Android isn't firing the delivery intent when sending a text message. I'm testing this on Android 2.2 on the HTC EVO 4G.

This is the current code. I'm seeing "SMS sent intent received." in the logs, but not "SMS delivered intent received.".

// Constants
String SENT_ACTION = "SMS_SENT_ACTION";
String DELIVERED_ACTION = "SMS_DELIVERED_ACTION";
String CELL_NUMBER = "0000000000";
String MESSAGE = "Hello World!";

// SMS sent pending intent
PendingIntent sentIntent = PendingIntent.getBroadcast(this, 0,
        new Intent(SENT_ACTION), 0);

// SMS delivered pending intent
PendingIntent deliveredIntent = PendingIntent.getBroadcast(this, 0,
        new Intent(DELIVERED_ACTION), 0);

// SMS sent receiver
registerReceiver(new BroadcastReceiver(){
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "SMS sent intent received.");
    }
}, new IntentFilter(SENT_ACTION));

// SMS delivered receiver
registerReceiver(new BroadcastReceiver(){
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "SMS delivered intent received.");
    }
}, new IntentFilter(DELIVERED_ACTION));

// Send the SMS message
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(CELL_NUMBER, null, MESSAGE, sentIntent, deliveredIntent);
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
William
  • 15,465
  • 8
  • 36
  • 32
  • 3
    As of the current OS deployed in the Thunderbolt, HTC completely overrides all results of SMS sent and delivered intents. If the message succeeds the result codes can be responded to, but if the message fails HTC automatically overrides all result codes, your code will not fire, and automatically re-sends the message. Basically if your trying to code sent and received notifications for an SMS application your wasting your time on HTC devices! I'm going to try and send an email to HTC and if I get a response at all I'll be shocked. – Noah Seidman Mar 27 '11 at 11:18
  • Any response or new piece of news? – cprcrack Nov 01 '11 at 19:21
  • have a look at this discussion: http://code.google.com/p/android/issues/detail?id=2305 – mtekeli Aug 20 '12 at 09:12

1 Answers1

3

This is a very late answer. but, it may help someone.

that code which is in question works fine, but, only change required is change the delivery request code. both are not to be the same request codes.

Here it is... and run on a real device to see delivery report.

EditText edNumber = findViewById(R.id.edNumber);
EditText edMessage = findViewById(R.id.edMessage);

String number = edNumber.getText().toString().trim();
String message = edMessage.getText().toString().trim();

// set pendingIntent for sent & delivered

        PendingIntent sentIntent = PendingIntent.getBroadcast(this, 100, new 
Intent(SENT_ACTION), 0);

        PendingIntent deliveryIntent = PendingIntent.getBroadcast(this, 200, new 
Intent(DELIVERY_ACTION), 0);

        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Log.d("SMS ", "sent");
            }
        }, new IntentFilter(SENT_ACTION));

        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Log.d("SMS ", "delivered");
            }
        }, new IntentFilter(DELIVERY_ACTION));

        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(number, null, message, sentIntent, 
deliveryIntent);
Silambarasan
  • 645
  • 1
  • 7
  • 13