march 2014 meetup baug android and google app engine

Post on 12-May-2015

349 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Gaurang explains how you can use Google App Engine as a back end for your android mobile apps

TRANSCRIPT

Using Google Datastore for Android apps

Gaurang Kanvinde(gaurang.kanvinde@drawtyme.com)

An example of how Google Datastore was used for DrawTyme

(http://drawty.me/ua44g)

+

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

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

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

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

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

Understanding the code

• The Video class

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

Writing the API

• Defining the API class with @Api annotation

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

Writing the API

• Adding authenticated methods

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

Writing the API

• Adding unauthenticated methods

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

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!

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

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

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

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

It works!

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

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

Locating the Android code for Endpoints

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

And we are done!

• Have fun using Google App Engine!

• Contact meGaurang.kanvinde@drawtyme.comTwitter: @gaurangrk

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

top related