androidandroid-intentsmspdu

How "deliveryIntent" works in Android SMS framework?


Android documentation for SMSManagers sendTextMessage function

public void sendTextMessage (String destinationAddress, String scAddress, String text,         
PendingIntent sentIntent, PendingIntent deliveryIntent)

deliveryIntent if not NULL this PendingIntent is broadcast when the message is delivered to the recipient. The raw pdu of the status report is in the extended data ("pdu")

I could not understand if deliveryIntent is fired when SMS is delivered to destinationAddress or scAddress and what is the meaning of "raw pdu of the status report is in the extended data ("pdu")" and how to get that report? .

I appreciate your effort.


Solution

  • It is broadcast when message is delivered to destinationAddress.

    The PDU may be extracted from the Intent.getExtras().get("pdu") when registered BroadcastReceiver receives the Intent broadcast you define with PendingIntent.getBroadcast(Context, int requestCode, Intent, int flags). For example:

    private void sendSMS(String phoneNumber, String message) {      
        String DELIVERED = "DELIVERED";
    
        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
            new Intent(DELIVERED), 0);
    
        registerReceiver(
            new BroadcastReceiver() {
                @Override
                public void onReceive(Context arg0, Intent arg1) {
                    Object pdu = arg1.getExtras().get("pdu");
                    ... //  Do something with pdu
                }
    
            },
            new IntentFilter(DELIVERED));        
    
        SmsManager smsMngr = SmsManager.getDefault();
        smsMngr.sendTextMessage(phoneNumber, null, message, null, deliveredPI);               
    }
    

    Then you need to parse extracted PDU, SMSLib should be able to do that.