Giter VIP home page Giter VIP logo

calendarquickstart's Introduction

CalendarQuickStart

A sample and tutorial demonstrating the use of the Google Calendar API

Getting started

After reading this tutorial, you should be able to have a working Android project that uses the Google Calendar API. This tutorial assumes that you're using Android Studio (SDK 1.1 or later), as well as API 22 or later and the Google Play Services.

Google Play Services is a set of APIs to allow app developers to take advantage of existing Google products (like Gmail, Calendar and Maps) in their own mobile applications and possibly enriching the user experience and ability to share content.

Read more about it here.

Project setup

First of all, open Android Studio to create your app. Enter the application name and company domain, like yourdomain.com and the IDE will automatically setup the project's package name.

Click "Next", target Phone and Tablet and preferably select the latest SDK version (make sure it is API 11 or later!). Then select Blank Activity and finish the wizard.

Now, with the project open on the IDE, open the build.gradle file (make sure it is the module one), now add the following lines to the dependencies block:

compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.google.apis:google-api-services-calendar:v3-rev119-1.19.1'
compile 'com.google.api-client:google-api-client:1.19.1'
compile 'com.google.api-client:google-api-client-android:1.19.1'
compile 'com.google.api-client:google-api-client-gson:1.19.1'

Now right-click the build.gradle file in the file navigator and click "Synchronize buld.gradle".

Permissions and Manifest File

Now open your AndroidManifest.xml file and add the following code right after the manifest tag.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

And add the following code right before closing the application tag:

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

On to the next phase, when you will learn to setup the Google Calendar API, to finally make it all work!

API setup

Now, you need to get a SHA1 fingerprint:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v

Enter the password of your choosing and copy the SHA1 key. This key is gonna be useful throughout the development of your app but you CAN'T use it for production mode.

Go to your Google Developers Console and enable the Calendar API. After the setup is done, click on the "Consent screen" link, enter an email address and product name and save it!

After that, click on the "Credentials" link and press "Create new Client ID". Select the option "Installed application", this is the one you need when developing a native mobile app, and also select Android as the installed application type.

Enter the package name you obtained in the Project setup phase, and enter your generated SHA1 fingerprint. Now click "Create Client ID".

Run the app

Now that you have created the app and connected it to the Calendar API, go to the "Run" menu and click Run app! You can either plug your device to the computer and run the app on it or you can run it on the emulator (we ran it on a Nexus 5 5.1 emulator). Anyway, you gotta have Google Plays services installed in the system (in case you missed it, go to Tools -> Android -> SDK Manager, search for Google Play Services SDK and install it).

If you receive any error until this step, please submit an issue and we'll try help you as soon as possible.

Usage Flow

Now with the app installed on our device, we're going to experience the Google Calendar API usage by fetching our existing events from our Google account. If you don't have a gmail account, please create one.

Android01

  • Click on CalendarQuickStart App to launch the app

Android02

  • Enter your email and click NEXT

Android03

  • Enter your password and click NEXT

Android04

  • Click ACCEPT, this will allow the app to fetch your calendar data from your Google account.

Android05

  • Click MORE

Android05

  • Click NEXT

Android06

  • Choose your account and click OK

Android07

  • Accept permissions by clicking on OK

Android08

  • Existing events are returned in plain text. The CalendarQuickStart app has successfully downloaded your events through.

Desktop Calendar Gmail screenshot

Further Reading for Google Calendar API

If you got hooked and feel like going beyond this tutorial with Calendar integration (creating and updating events from your app, perhaps?), then you should definitely take a look at these links:

Contact

License

See LICENSE file.

calendarquickstart's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.