简体   繁体   中英

Android get .ics file for calendar events

I am able to fetch the calendar events from Android device using a calendar events cursor. But I want to extract it as a .ics file.

Is it possible to extract as .ics? If not can we generate a .ics file from the cursor?

I am expecting a .ics file which looks as below :

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

EDIT : Also further I want to group multiple calendar events into a single .ics file

You Have To Download BiWeekly.jar First 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);

                            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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