小编典典

如何使用带有flutter的URL_launcher包发送短信?

flutter

您好,我搜索了一个简单的示例(Android和iOS)以通过此程序包发送短信

https://pub.dartlang.org/packages/url_launcher

在插件页面中,我仅看到如何使用电话号码打开短信本机应用程序,但没有其他消息

sms:<phone number>, e.g. sms:5550101234 Send an SMS message to <phone 
number> using the default messaging app

阅读 831

收藏
2020-08-13

共1个答案

小编典典

在Android上,sms:支持完整的URI,您可以发送带有这样的正文(RFC5724)的消息:

 _textMe() async {
    // Android
    const uri = 'sms:+39 348 060 888?body=hello%20there';
    if (await canLaunch(uri)) {
      await launch(uri);
    } else {
      // iOS
      const uri = 'sms:0039-222-060-888';
      if (await canLaunch(uri)) {
        await launch(uri);
      } else {
        throw 'Could not launch $uri';
      }
    }
  }

在此处输入图片说明

iOS上,您只能使用The的数字字段URI

sms方案用于启动Messages应用程序。此类型的URL的格式为“
sms:”,其中是一个可选参数,用于指定SMS消息的目标电话号码。此参数可以包含数字0到9以及加号(+),连字符(-)和句点(。)。
URL字符串不得包含任何消息文本或其他信息

PS。要检查平台,可以使用dart.io库Platform

if (Platform.isAndroid) {

} else if (Platform.isIOS) {

}
2020-08-13