Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a calendar event on an Android device with a given date?

Tags:

android

From Stack Overflow question How to add calendar events in Android? I came to know how to add the calendar event, but with the specific time for starttime (with hour and minutes) and EndTime (with hour and minutes). How can we add?

like image 739
ranjit patel Avatar asked Aug 23 '11 11:08

ranjit patel


2 Answers

Do something like this. Here startDate is the time you want to start.

    long startTime,endTime;

    String startDate = "2011-09-01";
    try {
        Date date = new SimpleDateFormat("yyyy-MM-dd").parse(startDate);
        startTime=date.getTime();
    }
    catch(Exception e){ }

    Calendar cal = Calendar.getInstance();
    Intent intent = new Intent(Intent.ACTION_EDIT);
    intent.setType("vnd.android.cursor.item/event");
    intent.putExtra("beginTime",startTime);
    intent.putExtra("allDay", true);
    intent.putExtra("rrule", "FREQ=YEARLY");
    intent.putExtra("endTime", endTime);
    intent.putExtra("title", "A Test Event from android app");
    startActivity(intent);
like image 104
Rasel Avatar answered Nov 09 '22 12:11

Rasel


You can as well use a Calendar instance with the set(year, month, day, hourofday, minofday) method before putextra("beginTime");

like image 38
Alfred Avatar answered Nov 09 '22 11:11

Alfred