B4A Library Calendar Library

Having had a need to be able to create and delete calendar events I produced my first calendar library (most of the code I got from the net).
The functions are;
- this will return a 'Map' with the calendar Id and name. With this ID we can then create or delete events in this calendar.

CreateEvent(int CalID, String Title, String Desc, String Location, long StartTime, long EndTime, String RRule, boolean AllDay)
- used to create a calendar event using the calendar ID found above. At the moment the fields allowed are Calendar ID, TITLE, DESCRIPTION, LOCATION, STARTTIME, ENDTIME, Recurring Rule and ALLDAY.

Added with V1.1
CreateEventWithReminder(int CalID, String Title, String Desc, String Location, long StartTime, long EndTime, int ReminderTime, String RRule, boolean AllDay)
- used to create a calendar event using the calendar ID found above. At the moment the fields allowed are Calendar ID, TITLE, DESCRIPTION, LOCATION, STARTTIME, ENDTIME, Reminder Time, Recurring Rule and ALLDAY.

- using the calendar ID we can get a 'List' of all events for that calendar, items returned are the same as in the CreateEvent as well as the Event ID. the data is in the form of a List you just need to iterate thru it.

GetListofEventsforCalendarBetweenDates(int, long, long)
- As above but you can specify start and finish dates/time in milliseconds from epoch.

ListofEventsWithDescKeywordBetweenDates(int, String, long, long)
- similar to above but filter on 'string' in the Description field.

ListofEventsWithTitleKeywordBetweenDates(int, String, long, long)
- this time filter on Title field

- once you have the event ID you can delete it with this routine.

This library works on the "unofficial" google model which works directly on the calendars on the phone its self this then syncs up to your google account online. The advantage is no problems with authorization but it probably will not work with all phones. I do hope to create a similar one using the new API which will work on everything and will not stop working. I have tried it on a HTC Desire 2.2 and an Asus tablet 3.1? and it worked on both.

To use it in your program,
Dim Mycal As MyCalendar
myMap = Mycal.GetListOfAllCalendars(False)
Mycal.CreateEvent(1,"Test title 7","This is a test of the create event","At Work",(DateTime.Now ),(DateTime.Now + 3600000),False)
The code is well commented so should not be a problem.
Hope it is of use to someone, it has lots of expansion capability, update calendar event, add more fields to the create event routine, search on different fields etc.

Edit; Version 1.1 added,
  1. New module added to create events with reminder
  2. Added a recurring Rule field to the Create Event modules, see RFC 5545 - Internet Calendaring and Scheduling Core Object Specification (iCalendar) for all the many options available, it is then passed as a string e.g. "FREQ=MONTHLY;WKST=SU;BYDAY=2WE"
  3. Calendar Example attached, this demonstrates
    • Locating Calendar ID
    • Getting list of events for the selected calendar for the previous month.
    • Creating an event with a reminder
    • Creating an all day event
    • Creating a recurring event
The list of Calendars is loaded into a listview with the Calendar Name and ID.
A Preference Screen (AHPreferenceActivity) is also created to show how the calendar selection can be achieved thru a settings page on menu press.

Edit; Version 1.2 added.
  1. Updated to include the new Calendar API for Android 4 aka ICS
  2. Example program now shows events in a listview, a long_click gives the option to delete the event.
  3. To use the example program select the radio button for the required action then select the calendar you want this action on. The event list is not dynamic so after adding or deleting an event you will have to select read events for that calendar to update the listview.

Edit; Version 1.3 added see post #39 for details
  • New function 'ListExtendedCalendarEntryDetails(Value)' this returns a Map containing
    * hasAlarm
    * recurRule
    * duration
    * minutes
    * method
    * AttendeeName
    * AttendeeEmail
    * AttendeeStatus
  • Sorted bug where ICS did not get the recurring events.

Edit; Version 1.4 added
The bug that I thought I had fixed in v1.3 was not fixed this sorts it out (I hope)

Edit; Version 1.5 added
Details for recurring event now show the start and end time for the recurring event not the original event.

Edit; Version 1.6 added
Changed library to a process object. (no longer an activity object)

Edit; Version 1.7 added
Bug fixed where event timezone was not entered on pre 4.0 android non "all day" event.

Edit; Version 1.8 added
No change in functionality but now the events are returned sorted based on the date/time of the start of the event.

Edit; Version 1.9 added
The 2 create event methods now return the created event ID as a string

Edit; Version 1.11 added
Attached is an updated version of the library with 2 new functions;
GetEventDetails & UpdateEvent.
At the moment UpdateEvent allows you to change the
1) Title
2) Description
3) Location
4) StartTime
5) EndTime
If you do not want to change any of the first 3 pass "" for the relevant one.
To change the time set the ChangeTime Boolean to 'true' and pass both the start & end times. Both must be passed as the system can update both or neither not just one. If ChangeTime is set to 'false' a value must be still be entered in the StartTime & EndTime fields as the function still expects values even if they are not used. Normally I would not use the Boolean and just pass -1 for the time to indicate that it is not to be used but -1 is a valid time (1 millisecond before the epoch Jan 01 1970).

Fixed a bug where 'GetListOfAllCalendars(False)' only returned your "owned" calendars instead of all calendars.

Edit; Version 1.12 added See this post for some more detail
Added function 'GetExtendedListOfAllCalendars(int)'
This returns a LIST with the following calendar values
  • calID (long)
  • name (string)
  • displayName (string)
  • colourName (string)
  • location (string)
  • timezone (string)
  • accesslevel (string)
  • owner account (string)
The value passed in the function is the Access Level, details of the different values are contained in the info popup in B4A.
The Returned LIST can contain no calendars to many calendars depending on the Access Level used. If there is more then 1 calendar the group of 8 values for the additional calendars is repeated.


  • CalendarExample v1.2.zip
    9.5 KB · Views: 3,280
  • calendar2 V1.12.zip
    18.7 KB · Views: 1,904
  • calendar2_v1.13.zip
    20.4 KB · Views: 739
Last edited:


Active Member
Licensed User
I have just done a test with 4 overlapping events, #1 is an all day event, #2 is from 0800 to 1000, #3 is 0900 to 1100 and #4 is 1000 to 1200. If I use start date at midnight and end date at midnight (24 hours later) all 4 events are returned. If I use 0900 as start and 1100 as end then only event #3 is returned. This is using my formula, are your events normal events or recurring events and what timezone are you in, what version of android are you using. If you are in a non UTC timezone then you must add 'GetTimeZoneOffsetAt' to both the start time and end time to correctly get an all day event as it is based on UTC.


Active Member
Licensed User
Worked great in my Foryo device and GetListOfAllCalendars picked up "Contact's birthdays and events" calendar from gmail as a map "member"
Running JellyBean device does not show "Contact's birthdays and events" as one of my calendars in the returned map, even though it appears in the "supplied" S-Planner app (Galaxy S4)


Active Member
Licensed User
Great library! Amazing work!

I have a doubt... When I use the update event procedure and the old event had a start time and finish time, How can I do that the event is for all the day?

Thank you very much


Licensed User
Is it possible there is a sorting problem (at least with android 4.3)? I see you sort like this if the SDK >= 14:

 mCursor = cr.query(builder.build(),
      "dtstart ASC");

I wrote a similar function and used "begin ASC" instead of "dtstart ASC" and I think the events were sorted correctly.

mCursor = cr.query(builder.build(),
          "begin ASC");


Licensed User

I've developed an app which maintains a calendar up to 365 days into the future which uses this library to sync device calendars and works fine.

The app can create hundreds of entries and sync without issue with Google calendar no problem but when attempting to delete in bulk then Android generates notifications messages stating there are too many deletes and prompts the user how do they wish to proceed.

Is there any way of stopping the android notification as this does impact the user experience of my app and is not as seamlessly integrated into Google calendar as I'd wished?



Licensed User

We have Google calendar events with "extendedproperties" (name/value pairs) like "ID's", “descriptions” and other information write by our ERP system in Google Calendar using Google API Calendar 3.

We want to read this “extendedproperties” in our application created with Basic4Android. There is any way to read these properties with your Calendar Library??

Do you know any way to read our own extended properties from Calendar Events

Thanks in advance

Dim cr As ContentResolver
Dim u As Uri
Dim Crsr As Cursor
      Crsr = cr.Query(u,Null,"event_id = " & Value ,Null,Null)
    Dim i As Int
    For i = 0 To Crsr.RowCount - 1
         Crsr.Position = i
        Msgbox("name=" & Crsr.GetString("name"),"Evento ID")
        Msgbox("value=" & Crsr.GetString("value"),"Evento ID")
Last edited:


Active Member
Licensed User
I have read everything but my English is not so good. One question I could not answer. Is it possible to create a new calendar?

Roberto P.

Well-Known Member
Licensed User
hello, we have source Java library?
thank you very much


Well-Known Member
Licensed User
thank you for your library.
I have a question. Creating an all day event, how can I delete the "reminder"?

Lyndon Bermoy

Active Member
Licensed User
Hi. The library is good but im getting this error that the calendar is not displaying. how to fix this?


  • calendar error.png
    calendar error.png
    390.9 KB · Views: 267


Well-Known Member
Licensed User
Hello, does the library work with Android 4+?
Because I can't add an event to the calendar :(
Please, help


Well-Known Member
Licensed User
I don't have any error. Only, the library doesn't add the event to the calendar


Well-Known Member
Licensed User
Thank you, Edward, for this library. Great contribution.

I have not fully tested it. But what happened to version 2.0 (referenced here)?

Best regards.



Licensed User
Ive already fixed it on my side with a workaround, but it should also be fixed on yours cause workarounds are slower

that formula is wrong.
it should be (event.starttime >= starttime AND event.starttime <= endtime) OR (event.endtime >= starttime AND event.endtime <= endtime)


I found that if (event.starttime >= starttime AND event.starttime <= endtime), but event.endtime > endtime, the function "GetListofEventsforCalendarBetweenDates" will not included.

Is the formula better be (event.starttime >= starttime AND event.starttime <= endtime) OR (event.starttime < starttime AND event.endtime <= endtime)?

Last edited:


Well-Known Member
Licensed User
what returns:
GetListofEventsforCalendarBetweenDates ?

in details, please (i know return List, but from what is .... ?)



Active Member
Licensed User

I can run and install the calendar2 example without any problem but when I added a calendar2 activity module to my exiting project, I am getting the following error while compiling.
Compiling generated Java code.    Error
B4A line: 163
javac 1.7.0_25
src\rosteroid2\tc\gcal.java:503: error: cannot find symbol
_cat3.AddList2("CalendarNumber","Calenders","Select the required calendar","","",_tempmap);
  symbol:   method AddList2(String,String,String,String,String,Map)
  location: variable _cat3 of type PreferenceCategoryWrapper

Anyone can help? Thanks


Licensed User
It would be great if there is also a feature to specify the color of an event when creating it, or editing it.
Would that be possible?
Last edited:


Well-Known Member
Licensed User
It would be great if there is also a feature to specify the color of an event when creating it, or editing it.
Would that be possible?

i think you need to create question thread in android question forum