ExtendedCalendarView icon indicating copy to clipboard operation
ExtendedCalendarView copied to clipboard

Adding events to Calender

Open ghost opened this issue 9 years ago • 4 comments

I am trying to add the events to the calender , but i could not . Not sure where i am going wrong . Please help me in . .

In the manifest File , i have added the below code

<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

In the class file , i have added the code as follows ,

calender = (ExtendedCalendarView)findViewById(R.id.chargehis_calenderview);

    // Adding events
    ContentValues values = new ContentValues();
    values.put(CalendarProvider.COLOR, Event.COLOR_RED);
    values.put(CalendarProvider.DESCRIPTION, "Sample Description");
    values.put(CalendarProvider.LOCATION, "Sample Location");
    values.put(CalendarProvider.EVENT, "Test Event");

    Calendar cal = Calendar.getInstance();
    TimeZone tz = TimeZone.getDefault();

    //Day julianStartDay = new Day(getActivity(), 25, 2014, 04);
    cal.set(2015, 04, 25, 9, 0);
    int julianDay = Time.getJulianDay(cal.getTimeInMillis(), cal.getTimeZone().getOffset(0));

    values.put(CalendarProvider.START, cal.getTimeInMillis());
    values.put(CalendarProvider.START_DAY, julianDay);

    cal.set(2015, 04, 25, 13, 0);
    int endDayJulian = Time.getJulianDay(cal.getTimeInMillis(),TimeUnit.MILLISECONDS.toSeconds(tz.getOffset(cal.getTimeInMillis())));

    values.put(CalendarProvider.END, cal.getTimeInMillis());
    values.put(CalendarProvider.END_DAY, endDayJulian);

    Uri uri = getContentResolver().insert(CalendarProvider.CONTENT_URI,values);

But i am not seeing the event added to the calender , let me know where i am going wrong .

ghost avatar Apr 14 '15 11:04 ghost

you code looks correct, do you get any errors? also you do not need Calendar permissions unless you are writing to the google calendar

tyczj avatar Apr 15 '15 13:04 tyczj

I don't get any errors but the event is not getting added to the Calender . I could not see the Red dot in the CalenderView . Regarding the Permissions : i tried that thinking it might be the problem , but didn't help

ghost avatar Apr 15 '15 14:04 ghost

the red dot is probably on 25 may not on april

moutiahub avatar May 21 '15 19:05 moutiahub

I'm facing same above problem,there is no events showing in calender.please help me

NazarAbbas avatar Jun 23 '15 11:06 NazarAbbas