After I had successfully added the calendar application to my Android emulator running Android 2.2 (Froyo), I soon realized that I wasn’t able to create events in it because I had no calendars. Android gave me this nice message: You have no calendars.
Searching the web for this problem lead me to the need of creating a Google account that then could be synced with the emulator’s calendar. However, the sync did not work. After setting up the account under Settings - Accounts and sync - Add account - Google it didn’t show up in the sync settings and there was still no calendar created for it.
The Android documentation said that it would be possible to create a calendar in an application, so I tried that. Quite a few hours of trying and debugging later, I finally found this post on StackOverflow, that contains a list of all the needed fields and correct values for them: After adding an event to a user-created calendar in android,the event title doesn’t show up.
So here’s the final piece of code that adds a local calendar to the Android emulator:
ContentValues vals = new ContentValues();
Where calUri is something like
and account is an android.accounts.Account.
I’ve put the code into a small application that reads the available accounts and creates a local calendar via a simple click on a button.
- AddLocalCalendar.apk (incl. source).
Attention: Your emulator has to run Google APIs (Google Inc.) – API Level 8 and not Android 2.2 – API Level 8.