3

I tried to send group sms and it works fine. But, I want to know which numbers are received my sms on delivered status:

For know delivered status I used below code:

public class SMSdelivered extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub

            switch (getResultCode()) {
            case Activity.RESULT_OK:
                Toast.makeText(context, "SMS DELIVERED", Toast.LENGTH_SHORT).show();
               //want to display mobile number tooo
                break;
            case Activity.RESULT_CANCELED:
                Toast.makeText(context, "SMS NoT DELIVERED", Toast.LENGTH_SHORT)
                        .show();
                break;
            }

        }

    }

Currently SMS DELIVERED message displayed fine. But, here I want to display mobile number of delivered target. How can I get delivered target mobile number using broadcast receiver??

Any idea??

Thanks in advance..

Lokesh
  • 5,180
  • 4
  • 27
  • 42

1 Answers1

6

You could attach an extra to the Intent used to create the Delivered PendingIntent with the addressee's number, then retrieve it in your BroadcastReceiver.

Intent delivered = new Intent(ACTION_SMS_DELIVERED);
delivered.putExtra("addressee", number);
PendingIntent pendingDelivered = PendingIntent.getBroadcast(context, 0, delivered, 0);

In onReceive():

String number = intent.getStringExtra("addressee");
Mike M.
  • 38,532
  • 8
  • 99
  • 95
  • Thanks for reply, I tried this already but, intent.getStringExtra returns null value.. – Lokesh Apr 21 '14 at 08:25
  • 1
    `PendingIntent`s can be reused. Try calling `getBroadcast()` with `PendingIntent.FLAG_UPDATE_CURRENT` or `PendingIntent.FLAG_CANCEL_CURRENT` as the last parameter. – Mike M. Apr 21 '14 at 08:36