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