Hi,
the time required to finish sending a multipart message may vary quite a lot. (Up to several minutes.)
When sending multiply messages it is kind of important to follow the process and not overload the system. It is best not to send the next SMS until the previous one is finished. Since jBroadcastReceiver.Receiver fires for every part sent/delivered (depending on the packageDeliveredAction parameter) we need some additional information to decide which part is the last one. If we new the number of parts in advance it would be quite easy, all we need to do is to increase a counter every time jBroadcastReceiver.Receiver is executed and compare it to the the number of parts.
Something like this:
procedure TAndroidModule1.jBroadcastReceiver2Receiver(Sender: TObject; intent: jObject);
begin
Inc(Parts_Sent_Count);
if (jBroadcastReceiver(Sender).GetResultCode() <> RESULT_OK) then
begin
Handle_Failed_Message;
end
else if Parts_Sent_Count = Parts_Count then
Send_Next_Message;
end;
But how do we get the number of parts? It is quite easy, jSend_SMS could return it to the caller. If the result is 0, something went wrong, if it is grater than zero it is the number of parts:
public int jSend_SMS
(String phoneNumber,
String msg,
String packageDeliveredAction,
boolean multipartMessage
) { String SMS_DELIVERED
= packageDeliveredAction
; PendingIntent deliveredPendingIntent = PendingIntent.getBroadcast(this.GetContext(), 0, new Intent(SMS_DELIVERED), 0);
SmsManager sms = SmsManager.getDefault();
try {
if (multipartMessage)
{
ArrayList<String> messages = sms.divideMessage(msg);
partsCount = messages.size();
ArrayList<PendingIntent> deliveredPendingIntents = new ArrayList<PendingIntent>();
for (int i = 0; i < messages.size(); i++)
{
deliveredPendingIntents.add(i, deliveredPendingIntent);
}
sms.sendMultipartTextMessage(phoneNumber, null, messages, deliveredPendingIntents, null );
}
else
{
List<String> messages = sms.divideMessage(msg);
partsCount = messages.size();
for (String message
: messages
) {
sms.sendTextMessage(phoneNumber, null, message, deliveredPendingIntent, null );
}
}
return partsCount ;
return 0; //fail
}
}
This modification would not break any exisiting code.