diff --git a/app/src/main/java/com/termux/api/SmsSendAPI.java b/app/src/main/java/com/termux/api/SmsSendAPI.java index b2d8c7b..8603031 100644 --- a/app/src/main/java/com/termux/api/SmsSendAPI.java +++ b/app/src/main/java/com/termux/api/SmsSendAPI.java @@ -10,19 +10,28 @@ import com.termux.api.util.TermuxApiLogger; public class SmsSendAPI { - static void onReceive(TermuxApiReceiver apiReceiver, final Intent intent) { - ResultReturner.returnData(apiReceiver, intent, new ResultReturner.WithStringInput() { - @Override - public void writeResult(PrintWriter out) throws Exception { - final SmsManager smsManager = SmsManager.getDefault(); - String recipientExtra = intent.getStringExtra("recipient"); - if (recipientExtra == null) { - TermuxApiLogger.error("No 'recipient' extra"); - } else { - smsManager.sendTextMessage(recipientExtra, null, inputString, null, null); - } - } - }); - } + static void onReceive(TermuxApiReceiver apiReceiver, final Intent intent) { + ResultReturner.returnData(apiReceiver, intent, new ResultReturner.WithStringInput() { + @Override + public void writeResult(PrintWriter out) throws Exception { + final SmsManager smsManager = SmsManager.getDefault(); + String[] recipients = intent.getStringArrayExtra("recipients"); + + if (recipients == null) { + // Used by old versions of termux-send-sms. + String recipient = intent.getStringExtra("recipient"); + if (recipient != null) recipients = new String[]{recipient}; + } + + if (recipients == null || recipients.length == 0) { + TermuxApiLogger.error("No recipient given"); + } else { + for (String recipient : recipients) { + smsManager.sendTextMessage(recipient, null, inputString, null, null); + } + } + } + }); + } }