几秒钟后,添加到android日历中的事件会自动消失?

时间:2019-03-13 11:06:36

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

我想在Google日历中创建一个活动。以下代码成功创建了一个事件,我也可以获取创建的事件ID。当我打开谷歌日历时,我只能看到几秒钟的事件。一段时间后,它消失了。怎么了?

 try {

        long startMillis = 0L;
        long endMillis = 0L;

        try {
            SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm a", Locale.getDefault());
            String startDate = estimationListItems.geteSStart();
            startMillis = sdf.parse(startDate).getTime();

            String endDate = estimationListItems.geteSEnd();
            endMillis = sdf.parse(endDate).getTime();

            AppLogger.e("startMillis : " + startMillis);
            AppLogger.e("endMillis : " + endMillis);

        } catch (ParseException pe) {
            pe.printStackTrace();
            AppLogger.e("ParseException : " + pe.getMessage());
        }

        ContentResolver cr = context.getContentResolver();
        ContentValues values = new ContentValues();
        values.put(CalendarContract.Events.DTSTART, startMillis);
        values.put(CalendarContract.Events.DTEND, endMillis);
        values.put(CalendarContract.Events.TITLE, estimationListItems.getDisplayEId());
        values.put(CalendarContract.Events.DESCRIPTION, estimationListItems.getEuAddress());
        values.put(CalendarContract.Events.CALENDAR_ID, calendarId);
        values.put(CalendarContract.Events.ALL_DAY, false);
        values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());

        Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);

        long eventID = Long.parseLong(uri.getLastPathSegment());
        AppLogger.e(" Event  added: " + eventID);

        syncCalendar(context, String.valueOf(calendarId));
    } catch (SecurityException se) {
        se.printStackTrace();
    }

添加活动后,我将同步日历。

    private void syncCalendar(Context context, String calendarId) {

    Uri CALENDAR_URI = Uri.parse("content://com.android.calendar/calendars");
    ContentResolver cr = context.getContentResolver();
    ContentValues values = new ContentValues();
    values.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
    values.put(CalendarContract.Calendars.VISIBLE, 1);

    AppLogger.e("syncCalendar Success");

    cr.update(
            ContentUris.withAppendedId(CALENDAR_URI, Long.parseLong(calendarId)), values, null, null);
}

0 个答案:

没有答案