当用户点击我的应用程序中的按钮时,我尝试启动 gmail 应用程序。 I am using the URL launcher package 。现在,我正在 Android 上进行测试,当我启动 youtube 或 Spotify 的 URL 时,应用程序就会启动。但是,当我尝试通过 gmail 网址启动 gmail 时,它不起作用。
这是我正在使用的网址:“https://mail.google.com/mail/u/0/#search/thisisasearch”。它不是启动到应用程序,而是启动到浏览器。谁能帮我解决这个问题吗?
此外,如果有人知道如何在 iOS 上实现这一点,我们将不胜感激!
最佳答案
要打开应用程序的默认邮件,您可以使用以下代码
_sendMail() async {
// Android and iOS
const uri =
'mailto:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1165746265517469707c617d743f7e6376" rel="noreferrer noopener nofollow">[email protected]</a>?subject=Greetings&body=Hello%20World';
if (await canLaunch(uri)) {
await launch(uri);
} else {
throw 'Could not launch $uri';
}
}
除了邮件之外,您还可以发送如下 URI 来进行不同的操作
- 调用电话 - '电话:+电话号码'
- 对于短信 - 'sms:+phonenumber'
关于flutter - 无法在 flutter 中使用 URL 启动程序包启动 gmail 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63287334/