1
String[] projection = new String[] { "_id", "name" };
Log.d("projection",""+projection);
Uri calendars = Uri.parse("content://com.android.calendar/calendars");
Cursor managedCursor =
    managedQuery(calendars, projection, null, null, null);

if (managedCursor.moveToFirst()) {
    /* String calName; 
    String calId;*/ 
    int nameColumn = managedCursor.getColumnIndex("name");
    Log.d("nameColumn",""+projection);
    int idColumn = managedCursor.getColumnIndex("_id");
    do {
        calName = managedCursor.getString(nameColumn);
        Log.d("name",""+calName);
        calId = managedCursor.getString(idColumn);
        Log.d("calId",""+calId);
    } while (managedCursor.moveToNext());
}
try{
    ContentValues event = new ContentValues();
    event.put("calendar_id", calId);
    Log.d("calId",""+calId);
    event.put("title", "Event Title");
    event.put("description", "Event Desc");
    event.put("eventLocation", "Event Location");
    Calendar c = Calendar.getInstance();
    long date = c.getTimeInMillis();
    Log.d("date",""+date);
    event.put("dtstart", date);
    Log.d("date",""+date);
    event.put("dtend", date);
    Log.d("date",""+date);
    event.put("allDay", 1); 
    event.put("eventStatus", 1);
    event.put("visibility", 0);
    event.put("transparency", 0);
    event.put("hasAlarm", 1);
    Uri eventsUri = Uri.parse("content://com.android.calendar/events");
    Log.d("eventsUri",""+eventsUri);
    Uri url = getContentResolver().insert(eventsUri, event);
} catch ( IllegalArgumentException e){
    System.out.println(e.getMessage());
}

导致错误:

java.lang.IllegalArgumentException: Event values must include an event Timezone
4

1 回答 1

4

我有同样的问题

尝试使用此名称作为列名,而不是timezone

values.put("eventTimezone", TimeZone.getDefault().getID());

许多列名随着不同的操作系统版本而变化,请查看这篇文章

https://groups.google.com/forum/?fromgroups=#!topic/rhomobile/7VyEMeZNSWI

于 2012-11-09T12:32:53.020 回答