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
相关产品推荐
相关产品推荐

