读写日历日历

由网友(海是天空的泪)分享简介:我的目标是读写日历。我能够从内容读取数据://日历/日历和内容://日历/事件i am able to read data from the content://calendar/calendars and content://calendar/eventsString uriString = "content:...

我的目标是读写日历。

我能够从内容读取数据://日历/日历和内容://日历/事件

i am able to read data from the content://calendar/calendars and 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());

  }

 }

我也是在日历中插入新的记录,如:

i am also inserting new record in the calendar like :

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);

但它没有出现在日历。

but it is not appearing in the Calendar.

当我要在日历一样插入新的事件:

when i going to insert new events in Calendar like :

   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);

抛出异常列无效。

throwing exception that column is invalid.

这是如何可能的。 谢谢

how this possible. Thanks

推荐答案

日历内容提供商是不是Android SDK的一部分。它的Andr​​oid版本之间改变之前,并会再次这样做。它可能无法在某些设备上,他们已经取代了用自己的默认日历应用程序的工作。

The calendar content provider is not part of the Android SDK. It has changed between Android releases before and will do so again. It may not work on some devices where they have replaced the default calendar application with their own.

不要使用无证内容提供商。

该解决方案是相同the你问的问题32分钟previously - 使用谷歌日历的GData API来处理用户的日历

The solution is the same as the question you asked 32 minutes previously -- use the Google Calendar GData APIs to manipulate the user's calendar.

阅读全文

相关推荐

最新文章