Instructions for the Calendar V3 Android Sample
Warning
This sample is for illustrative purposes only. Please instead use the native
Calendar APIs like the
Calendar
Provider API.
Browse Online
Register Your Application
You first need to register your Android application and sign up for
access to the Google Calendar API in the Google APIs Console. First, you
need the "Signing certificate fingerprint (SHA1)" for the debug build:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1
Enter keystore password: android
And for the release build:
keytool -exportcert -alias androiddebugkey -keystore my-release-key.keystore | openssl sha1
Next, register in the Google APIs Console:
- Visit the Google apis
console
- If this is your first time, click "Create project..." Otherwise, click
on the drop down under the "Google apis" logo at the top left, and click
"Create..." under "Other projects"
- Click on "Services", and change the Calendar API status to "ON".
- Click on "API Access", and then on "Create an OAuth 2.0 Client
ID...".
- Enter a product name and click "Next".
- Select "Installed application", select "Android", enter
com.google.api.services.samples.calendar.android for "Package name".
- Note: The package name must be universally unique to
actually register an application. If you try
to register a package name in use, you may get an error reading "An
unexpected error has occurred." This sample has already been
registered, so you will need to change the package name.
- Paste the SHA1 fingerprint for the debug certificate above into "Signing
certificate fingerprint (SHA1)", and click "Create client ID".
- Click "Create another client ID..." and follow the directions
from the previous steps, but use the release certificate instead of the
debug certificate.
Checkout Instructions
Prerequisites: install Java 6, Mercurial (requires 1.6 or
higher). You may need to set your
JAVA_HOME and ANDROID_HOME.
cd [someDirectory]
hg clone https://code.google.com/p/google-api-java-client.samples/ google-api-java-client-samples
cd google-api-java-client-samples/calendar-android-sample
To enable logging of HTTP requests and responses (highly recommended
when developing):
adb shell setprop log.tag.HttpTransport DEBUG
Setup Project in Eclipse
Prerequisites: install Eclipse,
the Mercurial plugin
(optional), and the Android
plugin.
- Preferences:
- Android: setup SDK location
- Window > Android SDK Manager
- Check on "Google APIs" under "Android 4.1.6 (API Level 16)"
- Check on "Google Play services" under "Extras".
- Click on "Install X packages..."
- Import
calendar-android-sample project
- File > Import...
- Select "General > Existing Project into Workspace" and click
"Next"
- Click "Browse" next to "Select root directory", find
[someDirectory]/google-api-java-client-samples/calendar-android-sample
and click "Next"
- Click "Finish"
- Set up the Google Play Services SDK by following the instructions under "Setup":
- Clean Project (if compile error about missing gen directory)
- Select
calendar-android-sample project
- Project > Clean...
- Select "Clean projects selected below"
- Click on "OK"
- NOTE: you must use a physical device for developing and testing
because Google Play services cannot be installed on an emulator.
Read this page for more information on how to set up a device with Eclipse.
- Run
- Right-click on project calendar-android-sample
- Run As > Android Application
- Select the physical device and click OK.
- Sample the app by creating a new calendar using the Menu and
updating/deleting a calendar using a long-press. Be careful!
You are making real changes to the Google account used, so you may
want to use a test account. As you make changes in the app, you can
see the effect online at google.com/calendar.
Make sure you have Google Calendar set up beforehand for this account.