我的目标是阅读和编写日历. 我能够从内容中读取数据:// calendar / calendars和content:// calendar / events String uriString = "content://calendar/calendars"; Log.i("INFO", "Reading content from " + uriString); readCo
我能够从内容中读取数据:// calendar / calendars和content:// calendar / events
String uriString = "content://calendar/calendars"; Log.i("INFO", "Reading content from " + uriString); readContent(uriString); uriString = "content://calendar/events"; Log.i("INFO", "Reading content from " + uriString); readContent(uriString); private void readContent(String uriString) { Uri uri = Uri.parse(uriString); Cursor cursor = mContext.getContentResolver().query(uri, null, null, null, null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); String columnNames[] = cursor.getColumnNames(); String value = ""; String colNamesString = ""; do { value = ""; for (String colName : columnNames) { value += colName + " = "; value += cursor.getString(cursor.getColumnIndex(colName)) + " ||"; } Log.e("INFO : ", value); } while (cursor.moveToNext()); } }
我也在日历中插入新记录,如:
String calUriString = "content://calendar/calendars"; ContentValues values = new ContentValues(); values.put("name", "Code Generate Calendar"); values.put("displayName", "Code Generate Calendar"); values.put("hidden", 0); values.put("color", "-7581685"); values.put("access_level", "700"); values.put("selected", "1"); values.put("timezone", "Asia/Karachi"); Uri calendarUri = context.getContentResolver().insert( Uri.parse(calUriString), values);
但它没有出现在日历中.
当我要在日历中插入新事件时:
ContentValues values = new ContentValues(); values.put("calendar_id", 4); values.put("dtend", "1277337600000"); values.put("dtstart", "1277251200000"); // values.put("title", "first TEst event"); values.put("transparency", 1); values.put("selected", 1); values.put("color", "-16380578"); // values.put("lastDate", "6/25/2010"); //values.put("access_level", 700); values.put("eventStatus", 1); values.put("eventTimezone", "UTC"); values.put("timezone", "Asia/Karachi"); values.put("allDay", 1); String eventUriString = "content://calendar/events"; Uri eventUri = context.getContentResolver().insert( Uri.parse(eventUriString), values);
抛出该列无效的异常.
怎么可能.
谢谢
Do not use undocumented content providers.
解决方案与the question you asked 32 minutes previously相同 – 使用Google Calendar GData API来操纵用户的日历.