Flutter-url_launcher

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

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

            <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" />

上面标签中的就是我们需要知道的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';
}
}

作者:秋分落叶
链接:https://www.jianshu.com/p/483546ae2829

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值