Android获取日历事件的.ics文件

时间:2015-06-04 07:57:49

标签: android google-calendar-api icalendar android-calendar

我可以使用日历事件游标从Android设备获取日历事件。 但我想将其作为.ics文件提取。

是否可以提取为.ics?如果没有,我们可以从光标生成.ics文件吗?

我期待一个.ics文件,如下所示:

BEGIN:VCALENDAR
VERSION:1.0
BEGIN:VEVENT
CATEGORIES:MEETING
STATUS:TENTATIVE
DTSTART:19960401T033000Z
DTEND:19960401T043000Z
SUMMARY:Your Proposal Review
DESCRIPTION:Steve and John to review newest proposal material
CLASS:PRIVATE
END:VEVENT
END:VCALENDAR

编辑: 另外,我想将多个日历事件分组到单个.ics文件中

1 个答案:

答案 0 :(得分:0)

首先要下载BiWeekly.jar      http://sourceforge.net/projects/biweekly

                  ical = new ICalendar();// Creating ical object

                            VEvent event = new VEvent();

                            Summary summary = event.setSummary("Meeting");
                            Attendee attendee1=event.addAttendee(email);
                            Attendee attendee2=event.addAttendee(myEmail);
                            Location location=event.setLocation(venue);

                            summary.setLanguage("en-us");
                            start = dt;
                            event.setDescription(comments);
                            event.setDateStart(new DateStart(start, false));


                            try {
                                if(chosenFile!=null)
                                event.addAttachment(new Attachment("", chosenFile));// adding attachment
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            ical.addEvent(event);

                            String filePath =       
      Environment.getExternalStorageDirectory() + "/meetings.ics";
                            file = new File(filePath);
      File root = new File(Environment.getExternalStorageDirectory(), "Notes");
                if (!root.exists()) {
                    root.mkdirs();
                }
                File file = new File(root,"meetings.ics");
                Biweekly.write(ical).go(file);
                            if(!isConnected())
                                showdialog();
                            else
                            {

                                    // Taking the user to device calender to enable user to store the meeting in local calendar as well if he wishes to


                                    Intent calIntent = new Intent(Intent.ACTION_INSERT); 
                                    calIntent.setType("vnd.android.cursor.item/event");    
                                    calIntent.putExtra(Events.TITLE, "Meeting"); 
                                    calIntent.putExtra(Events.EVENT_LOCATION, venue); 
                                    calIntent.putExtra(Events.DESCRIPTION, comments);
                                    calIntent.putExtra(CalendarContract.Attendees.ATTENDEE_NAME, name); 
                                    calIntent.putExtra(CalendarContract.Attendees.ATTENDEE_EMAIL, email);
                                    calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, 
                                         start.getTime()); 
                                    calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, 
                                             start.getTime()+3600000);

                                    startActivityForResult(calIntent, 1);

                            }