Skip to content

Instantly share code, notes, and snippets.

@marufsharia
Last active April 3, 2020 21:47
Show Gist options
  • Save marufsharia/4b01a59fa7df110988b8089034b0e904 to your computer and use it in GitHub Desktop.
Save marufsharia/4b01a59fa7df110988b8089034b0e904 to your computer and use it in GitHub Desktop.
Add event and reminder in the calendar app in programmatically
public void SetEvent(View view) {
long timeInMilliseconds = 0;
String date = "2020-04-04";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date mDate = null;
try {
mDate = sdf.parse(date);
timeInMilliseconds = mDate.getTime();
System.out.println("Date in milli :: " + timeInMilliseconds);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar cal = Calendar.getInstance();
cal.setTime(mDate);
cal.set(Calendar.HOUR_OF_DAY, 8);
cal.set(Calendar.MINUTE, 00);
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, cal.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, false);
intent.putExtra(CalendarContract.Events.TITLE, "this is title");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment