在Android日历中添加事件日期和时间 [英] Adding events date and time in android calendar

查看:131
本文介绍了在Android日历中添加事件日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Android日历活动中添加以下日期和时间....

I am trying to add the following date and time in my android calendars event....

Title and description =  Events for test
Start Date = May 05, 2012, 07:10PM
End Date = May 06, 2012, 02:10PM

以下是我添加到事件的代码

Following is my code to add to events

                    long startTime = 0, endTime = 0;
                    Date d = new Date();
            startTime = d.parse(start);
            d.setTime(startTime);

            endTime = d.parse(end);
            d.setTime(endTime);

            Intent intent = new Intent(Intent.ACTION_EDIT);
            intent.setType("vnd.android.cursor.item/event");
            intent.putExtra(Events.TITLE, summary);
            intent.putExtra(Events.DESCRIPTION, summary);
            intent.putExtra(Events.EVENT_LOCATION, "");
            intent.putExtra(Events.DTSTART, startTime);
            intent.putExtra(Events.DTEND, endTime);
            intent.putExtra(Events.ALL_DAY, allDayFlag);
            intent.putExtra(Events.STATUS, 1);
            intent.putExtra(Events.VISIBLE, 0);
            intent.putExtra(Events.HAS_ALARM, 1);
            startActivity(intent);

但在事件详细信息页面中,我得到标题,单独的描述是正确的。在开始和结束日期的地方,我得到当前日期,作为开始和结束时间为下一个1小时的时间。

But in the Event details page i am getting the title, description alone to be in correct. In the place of start and end date i am getting the current date where as the start and end time to be of next 1 hr time.

任何人都可以说我什么错误在我的代码.....

Can anyone say me whats going wrong in my code.....

推荐答案

如果你得到如下数据 Date = 2012年5月5日,下午7:10 ,然后将日期转换为数字格式a May可以为05,并传递以下代码中的值。

if your are getting the data as follows Date = May 05, 2012, 07:10PM, then convert the date to be in number format a May to be 05 and pass the value in the following code.

Calendar beginCal = Calendar.getInstance();
                beginCal.set(year, mnth, day, hrs, min);
                startTime = beginCal.getTimeInMillis();

                Calendar endCal = Calendar.getInstance();
                endCal.set(year, mnth, day, hrs, min);
                endTime = endCal.getTimeInMillis();     

                Intent intent = new Intent(Intent.ACTION_INSERT);
                intent.setType("vnd.android.cursor.item/event");
                intent.putExtra(Events.TITLE, summary);
                intent.putExtra(Events.DESCRIPTION, summary);
                intent.putExtra(Events.EVENT_LOCATION, "");     
                intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginCal.getTimeInMillis());
                intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endCal.getTimeInMillis());
                intent.putExtra(Events.ALL_DAY, allDayFlag);
                intent.putExtra(Events.STATUS, 1);
                intent.putExtra(Events.VISIBLE, 0);
                intent.putExtra(Events.HAS_ALARM, 1);
                startActivity(intent);

这篇关于在Android日历中添加事件日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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