2015-06-04 50 views
0

我能夠使用日曆事件光標從Android設備獲取日曆事件。 但我想提取它作爲一個.ics文件。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文件

回答

0

你必須下載雙週首先的.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); 

          } 
+0

是否可以不使用第三帕蒂jar文件做了什麼? –

+0

不需要雙週刊Jar對於它,我可以幫助你,因爲我在應用程序中實現了同樣的功能 –