mirror of
https://github.com/danog/termux-api.git
synced 2025-01-22 21:31:10 +01:00
Support multiple recipients when sending SMS
This commit is contained in:
parent
151717e2fb
commit
a83a77c508
@ -10,19 +10,28 @@ import com.termux.api.util.TermuxApiLogger;
|
|||||||
|
|
||||||
public class SmsSendAPI {
|
public class SmsSendAPI {
|
||||||
|
|
||||||
static void onReceive(TermuxApiReceiver apiReceiver, final Intent intent) {
|
static void onReceive(TermuxApiReceiver apiReceiver, final Intent intent) {
|
||||||
ResultReturner.returnData(apiReceiver, intent, new ResultReturner.WithStringInput() {
|
ResultReturner.returnData(apiReceiver, intent, new ResultReturner.WithStringInput() {
|
||||||
@Override
|
@Override
|
||||||
public void writeResult(PrintWriter out) throws Exception {
|
public void writeResult(PrintWriter out) throws Exception {
|
||||||
final SmsManager smsManager = SmsManager.getDefault();
|
final SmsManager smsManager = SmsManager.getDefault();
|
||||||
String recipientExtra = intent.getStringExtra("recipient");
|
String[] recipients = intent.getStringArrayExtra("recipients");
|
||||||
if (recipientExtra == null) {
|
|
||||||
TermuxApiLogger.error("No 'recipient' extra");
|
if (recipients == null) {
|
||||||
} else {
|
// Used by old versions of termux-send-sms.
|
||||||
smsManager.sendTextMessage(recipientExtra, null, inputString, null, null);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user