Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 不将事件插入日历的代码_Android_Events_Insert_Calendar - Fatal编程技术网

Android 不将事件插入日历的代码

Android 不将事件插入日历的代码,android,events,insert,calendar,Android,Events,Insert,Calendar,有人知道为什么这段代码没有将事件插入日历吗?我没有错误,只是没有插入事件 我正在使用galaxy s2和ICS更新,不确定这是否相关,但只是想知道这是否与谷歌日历应用程序无关 public void addEvent(Context ctx, String title, Calendar start, Calendar end) { Log.d(TAG, "AddUsingContentProvider.addEvent()"); TextView calendarList =

有人知道为什么这段代码没有将事件插入日历吗?我没有错误,只是没有插入事件

我正在使用galaxy s2和ICS更新,不确定这是否相关,但只是想知道这是否与谷歌日历应用程序无关

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(),如下所示:

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

在查找事件时也要检查,因为某些java日历/日期函数的月索引为0。因此,您将11月设置为12月而不是11月。以防万一..

不确定是否已解决。尝试了以下代码,它正在4.0上运行 注意,本月以0为基础,因此2103,12,决定于2014年1月20日 {

试试这个:

calEvent.put(CalendarContract.Events.EVENT_TIMEZONE, CalendarContract.Calendars.CALENDAR_TIME_ZONE);
工作起来很有魅力

calEvent.put(CalendarContract.Events.EVENT_TIMEZONE, CalendarContract.Calendars.CALENDAR_TIME_ZONE);