Flutter 入坑记FlutterFlutter学习

flutter 跳转到其他APP的两种方式

2019-07-03  本文已影响1人  雪纳瑞的哈士奇

废话不多 代码里说

方法1:使用url_launcher:

if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
//URL是一个字符串  一般是 scheme + host

但是我在使用这个方法的时候有部分APP使用不了 可能是这些APP的主页面没有设置scheme和host吧 所以我使用了下面这种方式

方法2:使用linker

if (Platform.isAndroid) {//判断是否是android平台
      try {
        await Linker.startActivity(new Intent.callApp(packageName: 包名,className: activity的绝对路径));
      } on PlatformException catch (e) {
        print("Open failed $e");
      }
    }

这种方法是通过报名打开的 同时也支持iOS 但是不是用报名(iOS没有包名不是) 下面我会继续写打开公众号 所以以后会更新

上一篇 下一篇

猜你喜欢

热点阅读