The Blog

Add Events on Google Calendar on Android Froyo and above

09 Ago 10

Since i started developing applications for android i noticed there were some undocumented apis. Google does reccomend to not use these apis but since there are no “other nice ways” to achieve some tasks sometimes they are useful ( but still unreccomended)

It’s the case of the Google Calendar Apis. Out there you can find a lot of docs about these undocumented & unsupported apis but you’ll get some troubles if google decides to change them.

For example if you want to add an “event” to the calendar programmatically you can follow the snippet below which is SDK proof. In fact i did ( It’s not refactored for better reading ) write some code that would work on Sdk from 1.5 to 2.2 ( aka Froyo ) solving the provider issue on froyo and above.


Hope it helps to solve the problem about google calendar in froyo πŸ™‚

Reference to the CP: Xda

Comments

  • Maurilios

    Very good tutorial. I would suggest a tip to improve your script; using parameter “selected=1” just after the projection String, will get a list of active calendars only.

  • Guillaume

    Good tutorial indeed, used the calendar before Froyo and it worked but not anymore, didn’t know why so thanks (didn’t try it yet though)!

    I think there is an error on line 40 though, as it should be:

    newEvent = cr.insert(Uri.parse(“content://com.android.calendar/events”), cv);

  • Guillaume

    Sorry, as it is:

    newEvent = cr.insert(Uri.parse(“content://com.android.calendar/events”), cv);

    but should be:

    newEvent = cr.insert(Uri.parse(“content://calendar/events”), cv);

  • I’m not sure it would work…. Have you tried it?

  • Guillaume

    Not yet, but it seems logical when reading the code (Froyo seems to remove the com.android. from the content address), otherwise why put an if – else with both the same instruction?

  • T

    @Guillaume : You are right. It is newEvent = cr.insert(Uri.parse(β€œcontent://calendar/events”), cv);, tested on 1.6 and it works.

    Tahnk you Andrea for such a great entry. It helps me a lot.

  • Lol @Guillame you’re right πŸ™‚ my fault i’ll clean the code asap.

    @T, you’re welcome πŸ™‚

  • Glad I found this tidbit on bing when I was perusing the web. Good STUFF!

  • Thank you
    This is a very helpfull tutorial.

  • MissLulu

    Hy, Good tutorial and its very usefull !
    I have a question about the parameters of the function. Could you please explain me, what it is context and the the number of milliseconds since Jan. 1, 1970, midnight GMT.
    Could you send me an example?

    thanks a lot