Apps
Apps

Reputation: 3389

Add appointment to android calendar

I need to add an appointment to android phone's calendar. I'm using the following code to add and appointment to the native calendar on my android phone.Android API Level is 7

Intent nativeIntent = new Intent(Intent.ACTION_EDIT);
nativeIntent.setType("vnd.android.cursor.item/event");


nativeIntent.putExtra("beginTime", getDateInMs("05/14/2012"+" "+"05:00 AM"));           
nativeIntent.putExtra("rrule", "FREQ=YEARLY");
nativeIntent.putExtra("endTime", getDateInMs("05/22/2012"+" "+"05:00 AM"));
nativeIntent.putExtra("title", "Test Appt"); 

((DroidGap)myactivity).startActivityForResult(this, nativeIntent, NATIVE_ACTIVITY_REQ_CODE);

private Long getDateInMs(String stringDateTime) throws ParseException {
    DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
    Date date = formatter.parse(stringDateTime);
    long dateInLong = date.getTime();
    return dateInLong;
}

This opens the calendar, but the end date is shown as Mon, May 14, 2012 6:00 AM. The start date and time is shown correctly. Could you please let me know if I'm doing it correctly?

Upvotes: 1

Views: 3971

Answers (1)

SeanPONeil
SeanPONeil

Reputation: 3910

Take a look at the Developer Docs for using the Calendar Content Provider http://developer.android.com/guide/topics/providers/calendar-provider.html#intent-insert

Upvotes: 1

Related Questions