Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Android™ Development

Reply
Contributor
Posts: 22
Registered: ‎02-26-2013
My Device: Z10
My Carrier: None
Accepted Solution

Calendar API - Insert is Weird and Cannot Query Calendar

Hello,

 

I am having some crazy trouble with the BB10 calendar for about 2-3 days now. I have tried ALL kinds of things but have run out of things to try.

 

Inserting

I can insert a Calendar event via context.getContentResolver().insert(eventsUri, eventValues). 

I can get the ID of the newly-inserted event via lastInsertId = Long.parseLong(eventUri.getLastPathSegment());


So far so good. Now, I know VIEW intents are *not* allowed (for bringing up the event in the calendar app) (http://developer.blackberry.com/android/apisupport/unsupportedapi_blackberry10_intents.html) so I tried to view the event manually by tapping on the calendar app.

 

I go to the event's Month but to my surprise there are NO EVENTS for that month, despite me getting a new "ID" for each event that I attempted to insert.

 

WEIRD PART


I can't really pin-point the how or why, but after some time (couple of hours usually or ... have no idea!!) *THE EVENT SHOWS UP*, except I'm not sure what caused it to show up and which event it is (because I have tried multiple attempts to add the calendar event). Then there is a case where multiple of such events show up in the same day (due to many attempts to insert). 

 

I AM BAFFLED!!! WTF?! The event I *just* added does not show up in the Calendar but I can get an event ID. For some strange reason, events decide to show up after some hours. WHAT IS GOING ON!?!

 

 

Querying


To help figure out why the events do not show up, I decided to query the calendar for that event.

 

You guessed it, 0 results, 0 row count, nothing shows up.

 

I use this code as a proof of concept:

 

Uri queryCalendar = Uri.parse("content://com.android.calendar/events");
Cursor cursor = getContentResolver().query(queryCalendar, null, null, null, null);

 

On Android, this code brings up ALL (ALL) calendar events.

On BB10, that code does JACK SQUAT!

 

PLEASE HELP, I cannot stress any more on this stupid implementation of Calendar. I have tried all kinds of URI's to fetch events, *including native BB10 URIs* that are supposed to run inside a native app, but NOTHING works.

 

I'd really really appreciate your help in figuring this out.

 

Sincerely,

Dritan

Contributor
Posts: 22
Registered: ‎02-26-2013
My Device: Z10
My Carrier: None

Re: Calendar API - Insert is Weird and Cannot Query Calendar

I read that there exists some sample code that has this part working.

 

Anyone know where to find this sample code?

Retired
Posts: 264
Registered: ‎01-08-2013
My Device: BlackBerry 10 Dev Alpha B
My Carrier: Bell

Re: Calendar API - Insert is Weird and Cannot Query Calendar

Hey Dritan,

 

Programmatically inserting Calendar events via Android code is not supported.

 

We do support invoking the native Calendar app to allow the user to enter event details though.

 

Though I am working to put up a sample, here's a quick snippet:

 

                final Intent calendarIntent = new Intent("android.intent.action.EDIT");
                calendarIntent.addCategory("android.intent.category.DEFAULT");
                calendarIntent.setType("vnd.android.cursor.item/event");
                startActivity(calendarIntent);

 

    Justin

 

 

Justin Jasmann | Android Application Development Consultant
Developer Relations
developer.blackberry.com
Contributor
Posts: 22
Registered: ‎02-26-2013
My Device: Z10
My Carrier: None

Re: Calendar API - Insert is Weird and Cannot Query Calendar

Thank you for your reply Justin!

 

I definitely got the calendar app to show up with a title, description, location, start time and end time. 

There is another field RRULE that calendars use to define the repetition and frequency of the event. This field is parsed just fine when passed -like the code below- in other platforms, but it's not showing up on this android-port. 

 

final Intent calendarIntent = new Intent("android.intent.action.EDIT");
calendarIntent.addCategory("android.intent.category.DEFAULT");
calendarIntent.setType("vnd.android.cursor.item/event");
calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calStart.getTimeInMillis())
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, calEnd.getTimeInMillis())
.putExtra("title", calEvent.get("SUMMARY"))
.putExtra("description", calEvent.get("DESCRIPTION"))
.putExtra("eventLocation", calEvent.get("LOCATION"))
.putExtra("rrule", calEvent.get("RRULE"));

 

 

Would you have any code that either works, gets around it not working or maybe even an easter-egg hack I'll take to get this working!

 

Thanks!

Dritan

Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: Calendar API - Insert is Weird and Cannot Query Calendar

I don't think this was supported. You can file a JIRA item and we'll see what can be done about it (basically, if this is already supported in the calendar card invoke then it should be easy for us to hook up, otherwise we have to lobby for it Smiley Happy)
Contributor
Posts: 22
Registered: ‎02-26-2013
My Device: Z10
My Carrier: None

Re: Calendar API - Insert is Weird and Cannot Query Calendar

[ Edited ]

Thanks for your reply.

 

Hmm RRULE is a standard field when invoking calendars, and Android will accept it when firing a calendar intent.

 

I'm not quite sure how a JIRA web plugin would help, I don't think I get what you mean, but I'd like to file whatever is needed to get this to work (even though there would most likely have to be an update to BB10 before seeing this change).

Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: Calendar API - Insert is Weird and Cannot Query Calendar

I mean to say if you can do it natively, we can probably easily hook it up in Android (since we use the native API ourselves to invoke the calendar card).

Contributor
Posts: 22
Registered: ‎02-26-2013
My Device: Z10
My Carrier: None

Re: Calendar API - Insert is Weird and Cannot Query Calendar

I believe it can be done natively, it's a pretty standard rule for ICS/VCS files. If it didn't then you'd never be able to set events that repeat natively on the BB10. I'll have to take a really long break from work while I wait for this patch, best excuse ever!

 

but on the other hand, here's a snipet from above which sets the event start and event end days.

 

putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calStart.getTimeInMillis())

putExtra(CalendarContract.EXTRA_EVENT_END_TIME, calEnd.getTimeInMillis())

 

I have tested on these devices: 

Q10 OS version 10.1.0.1483 and 10.1.0.1720
Z10 OS version 10.1.0.1720 

 

...and no luck. The date is always set to be today's date, current base time, floor to ceil.

 

Any idea about this one?

 

Thanks! Smiley Happy

 

 

 

 

 

Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: Calendar API - Insert is Weird and Cannot Query Calendar

[ Edited ]

I mean does the calendar add event card expose a way for me to tell it that it should be a repeating event, etc.  I will have to look into this.

 

Also, our support for calendar in general is a tad shoddy (i.e. undocumented) on 10.1.

 

10.2 supports CalendarContext.EXTRA_EVENT_BEGIN_TIME / EXTRA_EVENT_END_TIME.  10.1 you can use "dtstart" and "dtend" (aka Events.DTSTART / DTEND, and it's String data).  We still support dtstart / dtend in 10.2 but if you set both we will use EXTRA_EVENT_BEGIN_TIME / EXTRA_EVENT_END_TIME (the proper, documented way to do this).

 

EDIT: i.e. http://developer.blackberry.com/html5/apis/blackberry.invoke.card.calendarcomposeroptions.html and http://developer.blackberry.com/cascades/documentation/device_platform/invocation/calendar.html implies repetition isn't an option.  I'll log a feature request for this.

 

EDIT2: ^^^ those links should give you an idea of how to format the date if you use dtstart / dtend.

Contributor
Posts: 22
Registered: ‎02-26-2013
My Device: Z10
My Carrier: None

Re: Calendar API - Insert is Weird and Cannot Query Calendar

Thank you bbenninger for your reply.

 

I have tried your recommendation, checked out the links, tried to put the RRULE into the "start" and "startTime" fields, as well as "dtstart" and "dtend" as well as "beginTime" and "endTime" in the intent for starting the calendar app but no luck, start and end date time are set for now and no frequency Smiley Sad

 

I think it's a waiting game for me at this point.

 

Thanks for your help,

Dritan