如何在Android设备上添加一个日历事件与给定的日期? [英] How to add a calendar event on an Android device with a given date?

查看:158
本文介绍了如何在Android设备上添加一个日历事件与给定的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从堆栈 溢出问题的 如何在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?

推荐答案

做这样的事情。这里的startDate是要启动的时间。

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);

这篇关于如何在Android设备上添加一个日历事件与给定的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆