code不插入事件到日历 [英] Code not Inserting the Event into the Calendar

查看:105
本文介绍了code不插入事件到日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人明白为什么这code未插入事件到日历?我没有任何错误,它只是不插入事件?

Does anyone see why this code is not inserting the event into the calendar? I have no errors, it just doesn't insert the event?

我使用的是GALAXY S2与ICS更新,不知道这是相关的,但只是想知道是否有什么关系呢不是作为谷歌日历应用程序。

I'm using the galaxy s2 with the ICS update, not sure if this is relevant but just wondering if it has something to do with it not being the Google calendar app.

public void addEvent(Context ctx, String title, Calendar start, Calendar end) {
   Log.d(TAG, "AddUsingContentProvider.addEvent()");

TextView calendarList = 
    (TextView) ((Activity) ctx).findViewById(R.id.calendarList);

ContentResolver contentResolver = ctx.getContentResolver();

ContentValues calEvent = new ContentValues();
calEvent.put(CalendarContract.Events.CALENDAR_ID, 1); // XXX pick)
calEvent.put(CalendarContract.Events.TITLE, title);
calEvent.put(CalendarContract.Events.DTSTART, start.getTimeInMillis());
calEvent.put(CalendarContract.Events.DTEND, end.getTimeInMillis());
calEvent.put(CalendarContract.Events.EVENT_TIMEZONE, "Canada/Eastern");
Uri uri = contentResolver.insert(CalendarContract.Events.CONTENT_URI, calEvent);

// The returned Uri contains the content-retriever URI for 
// the newly-inserted event, including its id
int id = Integer.parseInt(uri.getLastPathSegment());
Toast.makeText(ctx, "Created Calendar Event " + id,
    Toast.LENGTH_SHORT).show();

感谢你。

推荐答案

尝试,而不是加拿大/东方,timeZone.getID()是这样的:

Try instead of "Canada/Eastern" , timeZone.getID() like this:

TimeZone timeZone = TimeZone.getDefault();
values.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());

此外,当您要查找的事件,因为一些Java日历/日期函数有0索引month.So设置检查月11月没有november.Just的情况下。

Also check when you look for the event,because some java calendar/date functions have 0-indexed month.So you set the month 11 is december not november.Just in case..

这篇关于code不插入事件到日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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