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

From a question How to add calendar events in Android? I learned how to add a calendar event, but with a specific time to start (with hours and minutes) and EndTime (with hours and minutes). How can we add?

+7
source share
2 answers

Do something like that. 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); 
+4
source

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

+1
source

All Articles