The Calender Provider API can be used by applications and sync adapters.

Here are the rules for inserting a new event:

  • You must include CALENDAR_ID and DTSTART.
  • You must include an EVENT_TIMEZONE. To get a list of the system's installed time zone IDs, usegetAvailableIDs(). Note that this rule does not apply if you're inserting an event through the INSERTIntent, described in Using an intent to insert an event—in that scenario, a default time zone is supplied.
  • For non-recurring events, you must include DTEND.
  • For recurring events, you must include a DURATION in addition to RRULE or RDATE. Note that this rule does not apply if you're inserting an event through the INSERT Intent, described in Using an intent to insert an event—in that scenario, you can use an RRULE in conjunction with DTSTART and DTEND, and the Calendar application converts it to a duration automatically.
Calendar beginTime = Calendar.getInstance();beginTime.set(2012, 0, 19, 7, 30);Calendar endTime = Calendar.getInstance();endTime.set(2012, 0, 19, 8, 30);Intent intent = new Intent(Intent.ACTION_INSERT)        .setData(Events.CONTENT_URI)        .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis())        .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis())        .putExtra(Events.TITLE, "Yoga")        .putExtra(Events.DESCRIPTION, "Group class")        .putExtra(Events.EVENT_LOCATION, "The gym")        .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY)        .putExtra(Intent.EXTRA_EMAIL, "rowan@example.com,trevor@example.com");startActivity(intent);
static Uri asSyncAdapter(Uri uri, String account, String accountType) {    return uri.buildUpon()        .appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true")        .appendQueryParameter(Calendars.ACCOUNT_NAME, account)        .appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build(); }

Here is an example that shows how to open the Calendar to a particular date:

// A date-time specified in milliseconds since the epoch.long startMillis;...Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();builder.appendPath("time");ContentUris.appendId(builder, startMillis);Intent intent = new Intent(Intent.ACTION_VIEW)    .setData(builder.build());startActivity(intent);

Here is an example that shows how to open an event for viewing:

long eventID = 208;...Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);Intent intent = new Intent(Intent.ACTION_VIEW)   .setData(uri);startActivity(intent);

Here is an example of an intent that sets a new title for a specified event and lets users edit the event in the Calendar.

long eventID = 208;Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);Intent intent = new Intent(Intent.ACTION_EDIT)    .setData(uri)    .putExtra(Events.TITLE, "My New Title");startActivity(intent);

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android 接入微信分享
  2. Android Display System Surface Flinger
  3. Android之封装支付宝支付
  4. flutter调用android原生组件
  5. 在Android上面如何使用带有心跳检测的Soc
  6. Android:pt 、sp、dp之间的换算
  7. Android实现计算器布局(四种布局方式)之Lin
  8. android方向键被锁定的问题
  9. Android学习笔记(六)-文件操作与SDCard读写
  10. Android自定义Gallery,实现CoverFlow效果