栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何从Flutter应用程序打开应用程序?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何从Flutter应用程序打开应用程序?

我建议您使用url_launcher飞镖包。

这样,您可以使用所有url模式打开(

phone
,,
sms
甚至
maps
根据您的情况)。

为了在Android和iOS中打开Goog​​le Maps,您可以使用Hemanth Raj建议的常规Android Maps
URI模式

_openMap() async {    const url = 'https://www.google.com/maps/search/?api=1&query=52.32,4.917';    if (await canLaunch(url)) {      await launch(url);    } else {      throw 'Could not launch $url';    }  }

如果要在Android上做出选择,则可以使用常规

geo:
URI模式。

如果要专门打开iOS Maps API,则可以使用Cupertino Maps
URI模式

如果您选择区分Android和iOS(未在所有平台上都使用Google Maps Api模式),则还必须在打开的地图调用中按以下方式进行操作:

_openMap() async {    // Android    const url = 'geo:52.32,4.917';    if (await canLaunch(url)) {      await launch(url);    } else {      // iOS      const url = 'http://maps.apple.com/?ll=52.32,4.917';      if (await canLaunch(url)) {        await launch(url);      } else {        throw 'Could not launch $url';      }    }  }

或者,您可以在运行时使用

dart.io
Platform
类检查操作系统:

import 'dart:io';_openMap() async {    // Android    var url = 'geo:52.32,4.917';    if (Platform.isIOS) {      // iOS      url = 'http://maps.apple.com/?ll=52.32,4.917';    }    if (await canLaunch(url)) {      await launch(url);    } else {      throw 'Could not launch $url';    }  }

现在,我完成了软管维护(真正的任务……没有一些代码重构……^^’),我可以结束我的回答了。

正如我在开始使用url_launcher告诉您的那样,您可以使用所有URI模式来进行呼叫,发送短信,发送电子邮件等。

这里有一些代码可以做到这一点:

_sendMail() async {    // Android and iOS    const uri = 'mailto:test@example.org?subject=Greetings&body=Hello%20World';    if (await canLaunch(uri)) {      await launch(uri);    } else {    throw 'Could not launch $uri';    }  }  _callMe() async {    // Android    const uri = 'tel:+1 222 060 888';    if (await canLaunch(uri)) {      await launch(uri);    } else {      // iOS      const uri = 'tel:001-22-060-888';      if (await canLaunch(uri)) {        await launch(uri);      } else {        throw 'Could not launch $uri';      }    }  }  _textMe() async {    // Android    const uri = 'sms:+39 349 060 888';    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';      }    }  }

即使URI模式应该是标准(RFC)有时

authority
path
他们的部分可能的框架(Android或iOS)之间的差异。

因此,在这里我例外地管理不同的操作系统,但是,您可以使用

dart.io
Platform
类更好地做到这一点:

import 'dart:io'

然后在代码中:

if (Platform.isAndroid) {} else if (Platform.isIOS) {}

我建议您始终在两种环境中对其进行测试。

您可以在此处检查Android和iOS架构文档:

  • android
  • iOS

如果您想在Android中类似于startActivity(但仅适用于Android平台),则可以使用dart包android_intent。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/376394.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号