摆脱“出席?”在Android日历活动中,使用Calendar API

时间:2013-05-08 21:13:49

标签: android android-contentprovider google-calendar-api android-calendar

我正在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);
}

日历和事件按预期创建,但打开事件会显示一行名为“Attending”的行,其中有三个单选按钮:“Yes,Maybe和No”。

有没有办法摆脱这个行/单选按钮?无论如何,这种选择在本地日历中的事件中无论如何都不会产生影响,我认为......

我正在使用Android 4.0.4设备btw:)

1 个答案:

答案 0 :(得分:2)

添加这两行似乎解决了这个问题:

values.put(Events.ORGANIZER, calendarOwner);
values.put(Events.HAS_ATTENDEE_DATA, 1);

不太清楚为什么!

参考:https://gist.github.com/mlc/5188579