Skip to content Skip to sidebar Skip to footer

Add Event To Calendar Api 7

How can I add an event to calendar using a phone with API 7? Below is my try, but it doesnt work: Intent intent = new Intent(Intent.ACTION_INSERT) .setData(Calendar

Solution 1:

Try the below solution.

Intentintent=newIntent(Intent.ACTION_INSERT)
                .setType("vnd.android.cursor.item/event")
                .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis())
                .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis());

activity.startActivityForResult(intent, 100);

Solution 2:

Try this it will help ...

CalendarbeginTime= Calendar.getInstance();
        beginTime.set(yearInt, monthInt - 1, dayInt, 7, 30);



        ContentValuesl_event=newContentValues();
        l_event.put("calendar_id", CalIds[0]);
        l_event.put("title", "event");
        l_event.put("description",  "This is test event");
        l_event.put("eventLocation", "School");
        l_event.put("dtstart", beginTime.getTimeInMillis());
        l_event.put("dtend", beginTime.getTimeInMillis());
        l_event.put("allDay", 0);
        l_event.put("rrule", "FREQ=YEARLY");
        // status: 0~ tentative; 1~ confirmed; 2~ canceled// l_event.put("eventStatus", 1);

        l_event.put("eventTimezone", "India");
        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");
        }
        Uril_uri= MainActivity.this.getContentResolver()
                .insert(l_eventUri, l_event);

Post a Comment for "Add Event To Calendar Api 7"