Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am aware that this is an old post, but I found inspiration for optimizing the solution found in the answer given by Akash Takkar if anyone is in need of a solution in the near future.</p> <h2><strong>The issues</strong></h2> <hr> <p>Specically, I found a few issues in the original code:</p> <ol> <li>The loop for retrieving calendar events broke immaturely <ul> <li>Hereby, only events from the first calendar was retrieved</li> </ul></li> <li>The first event in each calendar was skipped by using eventCursor.moveToFirst(); which thereafter moves directly to the next event in the while loop</li> <li>The id of the calendars were not set correctly in the eventCursor <ul> <li>"Calendars._id=" + 1, should be "Calendars._id=" + id,</li> </ul></li> <li>It would be difficult for others to specify their own time range</li> <li>The current solution is not object oriented which would hold many advantages</li> <li>The readability and documentation is not the best</li> </ol> <h2><strong>The solution</strong></h2> <hr> <p>I have hereby created a Github Library which returns a list of event objects in a specified time range which can be found at:</p> <p><a href="https://github.com/david-laundav/CalendarService">https://github.com/david-laundav/CalendarService</a></p> <p>The source files can be found under "CalendarService/src/dk/CalendarService".</p> <p><strong>Use cases</strong></p> <p>The solution itself contains two different methods for different purposes.</p> <p><strong>First use case:</strong></p> <pre><code>CalendarService.readCalendar(class.this) // where class.this is either your class or the context </code></pre> <p>This method will return a list of events for +/- 1 day</p> <p><strong>Second use case:</strong></p> <p>You can also specify your own time range:</p> <pre><code>CalendarService.readCalendar(class.this, int days, int hours) </code></pre> <p>An example might be:</p> <pre><code>CalendarService.readCalendar(class.this, 2, 5) </code></pre> <p>In doing so will return a list of events from +/-2 days and +/- 5 hours.</p> <p>The service has been tested, but please tell me if you experience any issues.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload