我在Android Google日历中添加了这些代码,但是当我禁用SPlanner时它似乎没有添加。 Google Calendar和SPlanner存在一些问题吗?
// Format the start and end time
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
DateFormat formatter = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss", Locale
.getDefault());
formatter.setLenient(false);
Date startDate = formatter
.parse("2013-10-28 16:00:00");
beginTime.setTime(startDate);
startMillis = beginTime.getTimeInMillis();
Date endDate = formatter
.parse("2013-10-28 16:01:00");
endTime.setTime(endDate);
endMillis = endTime.getTimeInMillis();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART,
startMillis);
values.put(CalendarContract.Events.DTEND,
endMillis);
values.put(CalendarContract.Events.TITLE,
"Testing title");
values.put(
CalendarContract.Events.DESCRIPTION,
"Testing description");
values.put(
CalendarContract.Events.CALENDAR_ID,
calendarId);
values.put(
CalendarContract.Events.EVENT_TIMEZONE,
TimeZone.getDefault().getID());
values.put(
CalendarContract.Events.HAS_ALARM,
1);
Uri eventsUri = Uri
.parse("content://com.android.calendar/events");
ContentResolver cr = getContentResolver();
Uri uri = cr.insert(eventsUri, values);
String eventId = uri.getLastPathSegment();
// reminder insert
Uri REMINDERS_URI = Uri
.parse("content://com.android.calendar/reminders");
values = new ContentValues();
values.put("event_id",
Long.parseLong(eventId));
values.put("method", 1);
values.put("minutes", 10);
cr.insert(REMINDERS_URI, values);
Toast.makeText(getApplicationContext(),
"event id=" + eventId,
Toast.LENGTH_SHORT).show();