android - android日历中添加的事件几秒钟后会自动消失?
问题描述
我想在谷歌日历中创建一个活动。以下代码成功创建了一个事件,我也可以获得创建的事件 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);
}
解决方案
推荐阅读
- c# - dotnet core IdentityModel 不会内省从第三方 IDaaS 发出的令牌
- mysql - 优化两个表的 SQL 查询
- html - 使用复选框过滤图像后,如何将图像放置在砌体布局的同一行中?
- python - 创建全局变量与在函数之间传递变量
- python - Python嵌套字典“无”在完成迭代时出现
- python - 如果 commands.dm_only() 返回 false,则捕获错误
- python - flask 为视图设置一个基本子目录
- python - Python Socket 仅在程序结束后发送
- php - 无法创建表`issue`。`section_comments
- javascript - 如何根据子云功能删除 Firebase 中的某个父节点