【发布时间】:2016-03-10 13:57:52
【问题描述】:
案例 1 我在 Amazon AWS 上托管了一个日历事件 iCal .ics 文件,并且该文件的 HTTP URL 集成在我的 Android 应用程序中。
当用户点击 URL 时,会显示一个带有以下选项的意图选择器:
- 日历应用
- 用于下载文件的浏览器
当我选择 Google 日历时,它给我一个错误提示“无法启动活动”
当我选择 Chrome 时,文件会被下载,当用户点击下载的文件时,它会给出同样的错误“无法启动事件”
以下是使用桌面 chrome http 客户端 Postman 下载文件时的响应标头
Accept-Ranges → bytes
Content-Length → 959
Content-Type → application/octet-stream
Date → Thu, 10 Mar 2016 13:45:10 GMT
ETag → "5d48719213395a28e09e8adf01f6ce83"
Last-Modified → Wed, 09 Mar 2016 15:24:22 GMT
Server → AmazonS3
x-amz-id-2 → XXXXXXXXXXXXXXXXXXXXXXXXX
x-amz-request-id → XXXXXXXXXXXXXXXXXXX
案例 2 为了进行实验,我在本地 Apache 服务器上编写了一个简单的 PHP 脚本来下载相同的文件,而不是直接从 HTTP URL 访问文件
PHP 代码
<?php
$file = $_GET['file'];
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
文件下载成功,然后
- 点击下载的文件
- 从意图选择器中选择了 Google 日历
- 事件已成功添加到谷歌日历中
以下是使用 PHP 脚本时的响应头
Cache-Control → must-revalidate, post-check=0, pre-check=0
Connection → Keep-Alive
Content-Description → File Transfer
Content-Disposition → attachment; filename=World_Television_Premiere_of_House_Of_Cards_March_1213_5pm_on_Zee_Cafe.ics
Content-Length → 959
Content-Transfer-Encoding → binary
Content-Type → application/octet-stream
Date → Thu, 10 Mar 2016 07:27:15 GMT
Expires → 0
Keep-Alive → timeout=5, max=100
Pragma → public
Server → Apache/2.4.7 (Ubuntu)
X-Powered-By → PHP/5.5.9-1ubuntu4.14
任何人都可以帮助理解为什么事件没有保存或适用于案例 1 吗?
提前致谢。 请帮忙。
编辑
Android 设备:Nexus 6 (6.0.1)
谷歌日历应用:5.3.6-115544951-release
【问题讨论】:
-
流式传输它仍然有效吗?因为那对我不起作用。仅当我从 gmail 中打开 ICS 文件时,它才对我有用。尝试打开 ICS 的任何其他方式都会出现“无法启动事件”错误。你有一个我可以测试的对你有用的 URL 吗?谢谢!
标签: android google-chrome http-headers google-calendar-api icalendar