How to add calendar events in Android?

前端 未结 10 1318
太阳男子
太阳男子 2020-11-22 13:31

I\'m just getting up to speed on Android, and today in a project meeting someone said that Android has no native calendar app so users just use whatever calendar app they li

10条回答
  •  臣服心动
    2020-11-22 14:36

    if you have a given Date string with date and time .

    for e.g String givenDateString = pojoModel.getDate()/* Format dd-MMM-yyyy hh:mm:ss */

    use the following code to add an event with date and time to the calendar

    Calendar cal = Calendar.getInstance();
    cal.setTime(new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss").parse(givenDateString));
    Intent intent = new Intent(Intent.ACTION_EDIT);
    intent.setType("vnd.android.cursor.item/event");
    intent.putExtra("beginTime", cal.getTimeInMillis());
    intent.putExtra("allDay", false);
    intent.putExtra("rrule", "FREQ=YEARLY");
    intent.putExtra("endTime",cal.getTimeInMillis() + 60 * 60 * 1000);
    intent.putExtra("title", " Test Title");
    startActivity(intent);
    

提交回复
热议问题