Bartos
Bartos

Reputation: 1037

Android - insert calendar event

I try to insert new event to google calendar. My code looks like this :

@OnClick(R.id.add_event_button)
    public void addEvent() {
        CalendarDB calendar = (CalendarDB) mCalendarSpinner.getSelectedItem();
        String id = calendar.calendarId;
        ContentValues event = new ContentValues();
        event.put(CalendarContract.Events.EVENT_TIMEZONE, "Europe/Berlin");  // Here choose your location time zone

        event.put("calendar_id", id);
        event.put("title", "barteq calendar tutorial test");
        event.put("description", "This is a simple test for calendar api");
        event.put("dtstart", System.currentTimeMillis());
        event.put("dtend", System.currentTimeMillis() + 1800*1000);
        event.put("allDay", 0);
        event.put("eventStatus", 3);

        event.put("hasAlarm", 1);
        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);
        }

However I'm getting problem with id :

 java.lang.IllegalArgumentException: New events must specify a calendar id

I've checked it - I'm sending correct id - for example [email protected] so why google has problem with it ? Any ideas ? Thanks in advance

Upvotes: 1

Views: 621

Answers (1)

Ahmad Aghazadeh
Ahmad Aghazadeh

Reputation: 17131

Add this column specify a calendar id

event.put(CalendarContract.Events.CALENDAR_ID,1);

Upvotes: 1

Related Questions