sendSms method
Future<void>
sendSms({
- required String to,
- required String message,
- SmsSendStatusListener? statusListener,
- bool isMultipart = false,
- int subscriptionId = -1,
Send an SMS directly from your application. Uses Android's SmsManager to send SMS.
Requires SEND_SMS permission.
Parameters:
to
: Address to send the SMS to.message
: Message to be sent. If message body is longer than standard SMS length limits set appropriate value forisMultipart
statusListener
(optional) : Listen to the status of the sent SMS. Values can be one of SmsStatusisMultipart
(optional) : If message body is longer than standard SMS limit of 160 characters, set this flag to send the SMS in multiple parts.
Implementation
Future<void> sendSms({
required String to,
required String message,
SmsSendStatusListener? statusListener,
bool isMultipart = false,
int subscriptionId = -1,
}) async {
assert(_platform.isAndroid == true, "Can only be called on Android.");
bool listenStatus = false;
if (statusListener != null) {
_statusListener = statusListener;
listenStatus = true;
}
final Map<String, dynamic> args = {
"address": to,
"message_body": message,
"listen_status": listenStatus,
"sub_id": subscriptionId
};
final String method = isMultipart ? SEND_MULTIPART_SMS : SEND_SMS;
await _foregroundChannel.invokeMethod(method, args);
}