我正在 Android 设备上创建本地日历,并将事件插入其中。这是我的代码(现在使用虚拟数据):
public static Uri createCalendarWithName(Context ctx, String calendarName, String displayName, Account account) {
Uri target = Uri.parse(CalendarContract.Calendars.CONTENT_URI.toString());
target = target.buildUpon().appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, account.name)
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, account.type).build();
ContentValues values = new ContentValues();
values.put(Calendars.ACCOUNT_NAME, account.name);
values.put(Calendars.ACCOUNT_TYPE, account.type);
values.put(Calendars.NAME, calendarName);
values.put(Calendars.CALENDAR_DISPLAY_NAME, displayName);
values.put(Calendars.CALENDAR_COLOR, CALENDAR_COLOR);
values.put(Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
values.put(Calendars.OWNER_ACCOUNT, account.name);
values.put(Calendars.VISIBLE, 1);
values.put(Calendars.SYNC_EVENTS, 1);
values.put(Calendars.CALENDAR_TIME_ZONE, "Europe/Oslo");
//values.put(Calendars.ALLOWED_ATTENDEE_TYPES, "0");
Uri newCalendar = ctx.getContentResolver().insert(target, values);
return newCalendar;
}
public void addEventToCalendar(){
long calID = getLocalCalID();
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2013, Calendar.MAY, 5, 14, 30);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2013, Calendar.MAY, 5, 14, 55);
endMillis = endTime.getTimeInMillis();
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startMillis);
values.put(Events.DTEND, endMillis);
values.put(Events.TITLE, "Siste frist for å ettersende papirer");
values.put(Events.DESCRIPTION, "Hei!\n\n");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "Europe/Oslo");
Uri uri = cr.insert(Events.CONTENT_URI, values);
// get the event ID that is the last element in the Uri
long eventID = Long.parseLong(uri.getLastPathSegment());
Log.i("EventID", ""+eventID);
cr = getContentResolver();
values = new ContentValues();
values.put(Reminders.MINUTES, TimeUnit.MINUTES.convert(2, TimeUnit.DAYS));
values.put(Reminders.EVENT_ID, eventID);
values.put(Reminders.METHOD, Reminders.METHOD_ALERT);
uri = cr.insert(Reminders.CONTENT_URI, values);
}
日历和事件按预期创建,但打开事件会显示名为“参加”的行,其中包含三个单选按钮:“是、可能和否”。
有没有办法摆脱这个行/单选按钮?无论如何,这个选择不会对当地日历中的事件产生任何影响,我想......
我正在使用 Android 4.0.4 设备 btw :)