Flutter-url_launcher

作者: 秋分落叶 | 来源:发表于2019-03-14 14:24 被阅读0次

1.首先需要在我们项目的“pubspec.yaml”配置文件的dependencies中加入url_launcher插件的依赖“url_launcher: ^3.0.2”

2.打开别的APP

想要打开其他app,需要知道被打开app的scheme, 如果是自己的app,Android可以在Manifest中看到:

<intent-filter>

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />

                <category android:name="android.intent.category.BROWSABLE" />

                <data

                    android:host="li.zhuoyuan"

                    android:scheme="flutter" />

</intent-filter>

上面<data>标签中的就是我们需要知道的url中的东西, 定义了scheme为flutter, host为li.zhuoyuan. 记住这两个字段,在我们想打开这个app的地方需要。可以只定义scheme ,host为可选项。

那么,我们需要的url组成部分就是:scheme://host 如果有host的话。

注意:这里scheme为必填,host、path为选填。选填内容可以不填,但是一旦填上了就必须全部完全匹配才会成功拉起。

void _openOtherApp() async {

    const url = 'flutter://li.zhuoyuan'; //这个url就是由scheme和host组成的 :scheme://host

    if (await canLaunch(url)) {

      await launch(url);

    } else {

      throw 'Could not launch $url';

    }

  }

2.打开网址

_launchURL()async {

const url ='https://github.com/HitenDev/FlutterDragCard';

if (await canLaunch(url)) {

await launch(url);

}else {

throw 'Could not launch $url';

}

}

3.打电话

_launchTel()async {

const url ='tel:+1 555 010 999';

if (await canLaunch(url)) {

await launch(url);

}else {

throw 'Could not launch $url';

}

}

4.发短信

_launchSMS()async {

const url ='sms:+1 555 010 999';

if (await canLaunch(url)) {

await launch(url);

}else {

throw 'Could not launch $url';

}

}

5.发邮件

_launchMailto()async {

const url ='mailto:smith@example.org?subject=News&body=New%20plugin';

if (await canLaunch(url)) {

await launch(url);

}else {

throw 'Could not launch $url';

}

}

相关文章

  • Flutter-url_launcher

    1.首先需要在我们项目的“pubspec.yaml”配置文件的dependencies中加入url_launche...

网友评论

    本文标题:Flutter-url_launcher

    本文链接:https://www.haomeiwen.com/subject/qviqmqtx.html