简体   繁体   English

从网站将.ics下载到Android日历

[英]Download .ics from website to Android calendar

I have a problem with .ics files and the calendar on my smartphone. 我的智能手机上的.ics文件和日历有问题。 First, to create an ICS file and download it, I use this function : 首先,使用以下功能创建并下载ICS文件:

function createEventCalendar($start, $end, $description, $location) {
    $event = array();
    $rand = rand(5, 1000000000);

    $event['name'] = "event";
    $event['data'] = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//blabla//blabla//FR\nBEGIN:VEVENT\nDTSTAMP:".date('Ymd\THis')."\nSTATUS:CONFIRMED\nUID:".$rand."\nDTSTART:".date('Ymd\THis', strtotime($start))."\nDTEND:".date('Ymd\THis', strtotime($end))."\nSUMMARY:Rendez-vous assurance\nDESCRIPTION:".$description."\nLOCATION:".$location."\nEND:VEVENT\nEND:VCALENDAR\r\n";

    return $event;
}

public function downloadEventCalendar($event) {
    $eventname = $event['name'].'.ics';

    header("Content-Type: text/x-vCalendar");
    header("Content-Disposition: attachment; filename=\"".$eventname."\"");

    echo $event['data'];
    exit();
}

For my exemple the DTEND finish 1 hours after the DTSTART . 以我为例, DTENDDTSTART之后1小时完成。 My problem is when I download this file from my XPERIA and click on the event event.ics , i choose Default account : Calendar of the device and the event is never imported and the screen is blocked, as you can see : 我的问题是,当我从XPERIA下载此文件并单击event event.ics ,我选择“ Default account : Calendar of the device并且该事件从未导入,并且屏幕被阻止,如您所见:

屏幕在这张照片上被遮住了

Did I forget to add a parameter for android ? 我是否忘记为android添加参数? because it works for IOS. 因为它适用于IOS。

UPDATE : here the ICS generated code 更新 :这里是ICS生成的代码

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//blaBla//blaBla//FR
BEGIN:VEVENT
DTSTAMP:20150804T095037
STATUS:CONFIRMED
UID:495370174
DTSTART:20150901T120000
DTEND:20150901T130000
SUMMARY:My summary
DESCRIPTION:Description of the event
LOCATION:My calendar
END:VEVENT
END:VCALENDAR

Thanks 谢谢

There's several problems with your generated iCalendar file. 您生成的iCalendar文件存在一些问题。 I would suggest you try an online validator. 我建议您尝试使用在线验证器。 If you still have issues after that, you should share the actual generated iCalendar, not the code that generates it (especially if it's all on one line :/) 如果在那之后仍然有问题,则应该共享实际生成的iCalendar,而不是生成它的代码(特别是如果它们全部放在一行:/中)

Finnaly, i found a solution ! 好的,我找到了解决方案!

When i created the content of my file, i used \\n , we need to use \\r\\n at the end of each lines like this : 当我创建文件的内容时,我使用\\n ,我们需要在每行的末尾使用\\r\\n ,如下所示:

$event['data'] = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//blabla//blabla//EN\r\nBEGIN:VEVENT\r\nDTSTAMP:".date('Ymd\THis')."\r\nSTATUS:CONFIRMED\r\nUID:".$rand."\r\nDTSTART:".date('Ymd\THis', strtotime($start))."\r\nDTEND:".date('Ymd\THis', strtotime($end))."\r\nSUMMARY:my summary\r\nDESCRIPTION:".$description."\r\nLOCATION:".$location."\r\nEND:VEVENT\r\nEND:VCALENDAR";

And to download the file i use header, the right one is : 并下载我使用标题的文件,正确的是:

header("Content-Type: text/Calendar");
header("Content-Disposition: attachment; filename=\"".$eventname."\"");

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM