插入事件的日历应用程序出错

时间:2012-08-08 15:55:02

标签: android-emulator

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

1 个答案:

答案 0 :(得分:4)

我有同样的问题面

尝试将此名称用于列名而不是 timezone

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

许多列名称随着操作系统版本的不同而变化,请查看此帖子

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