如何在 Android 设备上添加给定日期的日历事件?

2024-07-01

来自堆栈溢出问题如何在Android中添加日历事件? https://stackoverflow.com/questions/3721963/how-to-add-calendar-events-in-android我开始知道如何添加日历事件,但具有开始时间(带有小时和分钟)和结束时间(带有小时和分钟)的具体时间。我们如何添加?


做这样的事情。这里的startDate是你想要开始的时间。

    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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Android 设备上添加给定日期的日历事件? 的相关文章

随机推荐