You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter应用通过Deep Linking打开Google日历创建事件页的问题

如何在Flutter中直接唤起Google日历的创建事件页面

要直接唤起Google日历APP的创建事件页面,核心是把原来的网页URL替换成Google日历的自定义URL Scheme,具体修改步骤如下:

1. 修改URL协议与参数映射

把原有的https://calendar.google.com/...网页地址,替换为googlecalendar://开头的Scheme格式,同时调整部分参数名称:

  • 协议头从https://calendar.google.com/calendar/u/0/r/eventedit改为googlecalendar://event?action=CREATE
  • 参数对应关系:
    • 原text → 改为title(事件标题)
    • 原details → 改为description(事件详情)
    • 原ctz → 改为timezone(时区)
    • dates参数格式保持不变(开始时间/结束时间,格式为YYYYMMDDTHHMMSS)
    • location参数直接保留(若有具体地点需填充值,空值可留空)

针对你提供的参数,修改后的URL为:

googlecalendar://event?action=CREATE&dates=20210226T033000/20210226T040000&timezone=Asia/Calcutta&title=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&description=Parth+Pitroda

2. 调整Flutter代码

更新launchUrl的Uri,同时建议添加网页版作为 fallback(避免用户未安装Google日历APP时无法打开):

final calendarAppUri = Uri.parse(
  'googlecalendar://event?action=CREATE&dates=20210226T033000/20210226T040000&timezone=Asia/Calcutta&title=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&description=Parth+Pitroda'
);

if (await canLaunchUrl(calendarAppUri)) {
  await launchUrl(
    calendarAppUri,
    mode: LaunchMode.externalApplication,
  );
} else {
  // 未安装Google日历则 fallback 到网页版
  final webCalendarUri = Uri.parse('https://calendar.google.com/calendar/u/0/r/eventedit?dates=20210226T033000/20210226T040000&ctz=Asia/Calcutta&location&text=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&details=Parth+Pitroda');
  if (await canLaunchUrl(webCalendarUri)) {
    await launchUrl(webCalendarUri, mode: LaunchMode.externalApplication);
  } else {
    throw '无法打开Google日历';
  }
}

3. 配置平台权限

需要在各平台的配置文件中添加对googlecalendar Scheme的支持:

Android(AndroidManifest.xml)

在<activity>标签内添加intent filter:

<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:scheme="googlecalendar" />
</intent-filter>

iOS(Info.plist)

添加LSApplicationQueriesSchemes数组,包含googlecalendar:

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>googlecalendar</string>
</array>

内容的提问来源于stack exchange,提问作者Binary_Beast

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 12:15:37