I try to set event on a calendar that is shared with me. I know that I should use id of the calendar. However I've got problem. Here's my code :
@OnClick(R.id.add_event_button)
public void addEvent() {
CalendarDB calendar = (CalendarDB) mCalendarSpinner.getSelectedItem();
Long id = calendar.getId();
ContentValues event = new ContentValues();
event.put("calendar_id", 1);
event.put(CalendarContract.Events.EVENT_TIMEZONE, "Europe/Berlin"); // Here choose your location time zone
event.put("title", "test application");
event.put("description", "This is test event");
event.put("eventLocation", "School");
event.put("dtstart", System.currentTimeMillis());
event.put("dtend", System.currentTimeMillis() + 1800 * 1000);
event.put("allDay", 0);
// status: 0~ tentative; 1~ confirmed; 2~ canceled
// event.put("eventStatus", 1);
event.put(CalendarContract.Events.CALENDAR_ID,8);
Uri l_eventUri;
if (Build.VERSION.SDK_INT >= 8) {
l_eventUri = Uri.parse("content://com.android.calendar/events");
} else {
l_eventUri = Uri.parse("content://calendar/events");
}
Uri l_uri = this.getContentResolver()
.insert(l_eventUri, event);
Toast.makeText(this, "SUCCESS", Toast.LENGTH_SHORT).show();
}
That works and event is being added however , the id's of the calendars are unknown - I mean I try to set them manually - 1,2,3 and so on and figure it out on which calendar event will be added. Google API site says that id should be Long , when I get calendar list I'm getting string as id - name of the calendar. The same situation is in android.provider CalendarContract.class :
public static final String CALENDAR_ID = "calendar_id";
When I set that id as a parameter the app crashes - it needs Long argument. So, how can I get id;s of the shared calendars ? Thanks in advance for help :)