Using Google Datastore for your Android app

18
Using Google Datastore for Android apps Gaurang Kanvinde ([email protected]) An example of how Google Datastore was used for DrawTyme (http://drawty.me/ua44g) +

description

This presentation was used for a talk I delivered at the March Meetup of Bangalore Android Users Group - http://drawty.me/12e9v. During this talk, I showed step-wise how we used Google Datastore and Google App engine for DrawTyme, and how you can easily do so too! For more details, follow the blog post - http://drawty.me/ua44g

Transcript of Using Google Datastore for your Android app

Page 1: Using Google Datastore for your Android app

Using Google Datastore for Android apps

Gaurang Kanvinde([email protected])

An example of how Google Datastore was used for DrawTyme

(http://drawty.me/ua44g)

+

Page 2: Using Google Datastore for your Android app

22-Mar-2014 2©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

Overview of Google Datastore

• Non-relational database• Cloud based• Ready to use• Requires Google App Engine and Google Endpoints

– Very inexpensive and simple to use– Can be programmed in many languages – Java, Python, etc– Extensive documentation available

Page 3: Using Google Datastore for your Android app

22-Mar-2014 3©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

The Development Environment

• Eclipse for Java EE - Download and install• Google Plugin for Eclipse – Instructions to install

Page 4: Using Google Datastore for your Android app

22-Mar-2014 4©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

Setting up Google App Engine

• Create a project on Google App Engine - Link to Console• Remember it’s Project-ID

Page 5: Using Google Datastore for your Android app

22-Mar-2014 5©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

The nuts and bolts

• Two main directories– src

• Contains all the code of the app– war

• Contains a sub-directory named WEB-INF– Contains the compiled binaries of the code in “src”– Contains other dependencies– Everything else that goes into the app

• Contents of this directory will be deployed to the Google App Engine– index.html (if any, will go here)

• Code available at: DrawTymeExample.zip

Page 6: Using Google Datastore for your Android app

22-Mar-2014 6©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

Understanding the code

• The Video class

Page 7: Using Google Datastore for your Android app

22-Mar-2014 7©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

Writing the API

• Defining the API class with @Api annotation

Page 8: Using Google Datastore for your Android app

22-Mar-2014 8©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

Writing the API

• Adding authenticated methods

Page 9: Using Google Datastore for your Android app

22-Mar-2014 9©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

Writing the API

• Adding unauthenticated methods

Page 10: Using Google Datastore for your Android app

22-Mar-2014 10©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

Preparing to Deploy

• Write app-ID of your project in war/WEB-INF/appengine-web.xml

Page 11: Using Google Datastore for your Android app

22-Mar-2014 11©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

Setting up Datastore Indexes

• war/WEB-INF/datastore-indexes.xml– If you get the contents of this file wrong, Google App Engine suggests

the correct content for you!

Page 12: Using Google Datastore for your Android app

22-Mar-2014 12©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

A quick peek at the Web-app

• war/js/backend.js– Initialising the API

Page 13: Using Google Datastore for your Android app

22-Mar-2014 13©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

A quick peek at the Web-app

• war/js/backend.js– Calling API functions

Page 14: Using Google Datastore for your Android app

22-Mar-2014 14©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

Deploying to App Engine

• Use Google Plugin button– Deploy to App Engine– Sign-in to the App Engine is required

Page 15: Using Google Datastore for your Android app

22-Mar-2014 15©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

It works!

Page 16: Using Google Datastore for your Android app

22-Mar-2014 16©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

Porting to Android

• AppEngine SDK has all the tools!– Use endpoints.cmd or endpoints.sh

• Eg: $PATH_TO_SDK/bin/endpoints.cmd get-client-lib \ com.example.api.classname

– Android code will be generated and stored in myapi-v1-java.zip

Page 17: Using Google Datastore for your Android app

22-Mar-2014 17©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

Locating the Android code for Endpoints

Page 18: Using Google Datastore for your Android app

22-Mar-2014 18©2014 DrawTyme Technologies Pvt. Ltd., All rights reserved

And we are done!

• Have fun using Google App Engine!

• Contact [email protected]: @gaurangrk

• DrawTymehttp://www.drawtyme.comTwitter: @drawtymeFacebook: https://www.facebook.com/drawtymeBlog: http://blog.drawtyme.com