在最新的android 4.0中,在日历方面新增加了相关的API,可以操作了,简单小结下.
1 创建一个日历的intent
Intent calIntent = new Intent(Intent.ACTION_INSERT); calIntent.setType("vnd.android.cursor.item/event");
startActivity(calIntent);
2 设置日历的具体信息
Intent calIntent = new Intent(Intent.ACTION_INSERT); calIntent.setType("vnd.android.cursor.item/event");
calIntent.putExtra(Events.TITLE, "My House Party");
calIntent.putExtra(Events.EVENT_LOCATION, "My Beach House"); calIntent.putExtra(Events.DESCRIPTION, "A Pig Roast on the Beach"); startActivity(calIntent);
3 设置日历事件提醒的具体时间
Intent calIntent = new Intent(Intent.ACTION_INSERT); calIntent.setType("vnd.android.cursor.item/event");
calIntent.putExtra(Events.TITLE, "My House Party");
calIntent.putExtra(Events.EVENT_LOCATION, "My Beach House"); calIntent.putExtra(Events.DESCRIPTION, "A Pig Roast on the Beach");
GregorianCalendar calDate = new GregorianCalendar(2012, 7, 15); calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true); calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calDate.getTimeInMillis()); calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
calDate.getTimeInMillis());
startActivity(calIntent);
可以看到,可以设置事件是在某个时间点开始和结束的
4 calIntent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE); calIntent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
calIntent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE); //设置只能私人看到事件
calIntent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
//设置其他事件不能覆盖它
5 设置事件定期提醒
calIntent.putExtra(Events.RRULE, “FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH”);
这个规则参考RFC 5544 ,比如上面是说每个星期二,星期四执行,总共执行10次,即5周