1
0
mirror of https://github.com/danog/termux-api.git synced 2025-01-22 13:21:10 +01:00

Support multiple recipients when sending SMS

This commit is contained in:
Fredrik Fornwall 2016-04-24 23:52:55 +02:00
parent 151717e2fb
commit a83a77c508

View File

@ -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);
}
}
}
});
}
}