5

i have read multiple threads on how to send and receive multipart messages. I have implemented the following code and it works!

      PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
      PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);
        //---when the SMS has been sent---
        registerReceiver(SMSBroadcastReceiver1, new IntentFilter(SENT));
        //---when the SMS has been delivered---
        registerReceiver(SMSBroadcastReceiver2, new IntentFilter(DELIVERED));    


    SmsManager smsManager = SmsManager.getDefault();
    ArrayList<String> parts = smsManager.divideMessage(smsToSend);

    ArrayList<PendingIntent> sentList = new ArrayList<PendingIntent>();
    ArrayList<PendingIntent> deliveredList = new ArrayList<PendingIntent>();
    for (int i = 0; i < parts.size(); i++) {
        sentList.add(sentPI);
        deliveredList.add(deliveredPI);
    }


    //smsManager.sendTextMessage(phoneNumber, null, smsToSend, sentPI, deliveredPI);
    smsManager.sendMultipartTextMessage(phoneNumber, null, parts, sentList, deliveredList);

and i have one registered SMSBroadcastReceiver2 and SMSBroadcastReceiver1.

The thing that worries me is:

I have one single PendingIntent sentPi and deliveredPi, that are registered with SMSBroadcastReceiver1 and SMSBroadcastReceiver2.

And then i put them in ArrayList's multiple times, depending on how long is the message.

Is this a good thing? Or should i have different Intents and Receivers for each part of the message.

Also when do receivers fire in my code? I have noticed it only fires once when the message is sent and once when its received(i coded them to display Toast Messages at those moments), no mater how long the message is. Is it when the first part is delivered or last...?

JanBo
  • 2,925
  • 3
  • 23
  • 32

0 Answers0