47
An Intertech Course Connecting Android to Windows Azure Windows Azure UG December 2012 Monthly Meeting

Connecting Android to Windows Azure

  • Upload
    jeneil

  • View
    58

  • Download
    0

Embed Size (px)

DESCRIPTION

Connecting Android to Windows Azure. Windows Azure UG December 2012 Monthly Meeting. Welcome to the Windows Azure UG. Presenter today Jim White – [email protected] Intertech Instructor & Director of Training Android and Azure instructor Practice lead for Cloud Computing at Intertech - PowerPoint PPT Presentation

Citation preview

Page 1: Connecting Android to Windows Azure

An Intertech Course

Connecting Android to Windows Azure

Windows Azure UGDecember 2012

Monthly Meeting

Page 2: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 2

Welcome to the Windows Azure UG• Presenter today

• Jim White – [email protected]• Intertech Instructor & Director of Training

• Android and Azure instructor• Practice lead for Cloud Computing at Intertech

• Windows Azure Bootcamp Facilitator• Author of Windows® Azure™ Solutions with Microsoft® Visual Studio® 2010

– in Microsoft Courseware Library this October

This presentation & sample codewill be made available through azureug.net

Page 3: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 3

Agenda• What is the Windows Azure Toolkit for Android• A quick Android tutorial• Setup

• Learn how to get & setup the WAT for Android• See how to setup the Cloud Ready Packages for Devices

• Building an Azure accessing Android application• Sample the WAT for Android API

• Authentication• Storage Access

• Witness some demos• Limitations & More Info• Q & A

Page 4: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 4

Assumptions• You already have a pretty good understanding of Windows Azure

• In particular, you understand Windows Azure Storage• I.e. – storage account creation, setup, API, etc.• You understand how to use the Management Portal

• You may have minimal or no Android development experience.• Given this is a Windows Azure UG, I’ll provide a little bit of a background

on Android development.• I.e. – where to get the Android SDK, how to set it up, how to get going.• Android is a Java platform. A Java tutorial is beyond the scope of this talk.

Survey 1 - background

Page 5: Connecting Android to Windows Azure

An Intertech Course

Windows Azure Toolkit for Android

Basics

Page 6: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 6

Windows Azure Toolkit (WAT) for Android• May 2011, MSFT announces Windows Azure Toolkits for Mobile

devices• iOS and Windows 7 Phone first• Android version released – Aug 31, 2011• Current version: 0.8

• Available as an open source product• Under the Apache License, Version 2.0

• Provides Android/Java libraries for:• Accessing Windows Azure Storage• Authentication (via various means)

Note: Windows Phone and iOS versions provide more capability (push notifications, SQL Azure access)

Page 7: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 7

WAT for Android• You could use Windows Azure RESTful API to do the same work.

• Would require a lot more work/maintenance

• WAT for Android Libraries• Written in Java – allow for native coding• Make it easy to are write/maintain Android apps• Obfuscates RESTful calls.• Will presumably offer even more features in the future

Page 8: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 8

Windows Azure Storage Access• WAT for Android provides Java libraries to access

• Table Storage• Queue Storage• Blog Storage• No SQL Azure access at this time

• Before accessing, your application must authenticate• Directly (using storage account id and key)• Via proxy service

Page 9: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 9

Authentication• WAT for Android provides three (3) Authentication Options

• Direct access: requires the application know Windows Azure Storage account and key (not a best practice)

• Use a membership service: applications need/use service URL and username/password

• Use a Windows Azure Access Control Service (ACS): applications need/use federated/social identity

• Last two (2) options require proxy service• Provide via Cloud Ready Package for Mobile Devices

Page 10: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 10

Authentication – via Direct Access• Java application has or is provided

account URL/key.• Easy to setup, test, etc.• Security concerns

• Account “secrets” in the app• Access revocation is difficult

• Maintenance concerns• Account changes• Storage changes

Page 11: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 11

Authentication – via Membership• Available through Cloud Ready Packages for Devices

• ASP.NET Web Role provides membership management• Registration, password selection, access and user management, etc.

• Users create account through Web role or through your application if you provide the means (see the sample application)

• Mobile devices use account to get authentication token to access Windows Azure

• More work to setup• Applications know nothing about account (except membership URL)• Membership management an issue for large user bases

Page 12: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 12

Authentication – via ACS • Available through Cloud Ready Packages for Devices

• Users must have federated/social identity (Windows Live ID, Facebook, Google, etc.)

• Setup a Window Azure Access Control Service Namespace with Multiple Identity Providers in your account

• Hosted service authenticates through ACS/Identity providers

• ACS setup is a bit complex• Application knows nothing about account (except service URL)• No membership management (excellent for large user bases)

Page 13: Connecting Android to Windows Azure

An Intertech Course

Android Development

Tutorial

Page 14: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 14

Android Development – The Basics• Android Architecture• Android Development – what you need• Emulators• Android Versions and Platforms• Android Project• Android Applications• Android Market (and other deployments)• Further Android Resources

Survey 2 – Android Knowledge

Page 15: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 15

Android Architecture• Write applications in Java

• Java code is compiled to bytecode (.class)…• …then into .dex (Dalvik executable) files run by DVM

• Application Framework• Minus some Java SE libraries/classes• Plus many Android libraries

• Android Runtime• The Dalvik Virtual Machine + core Java libraries• Not a standard “Java” virtual machine• Java coding, but not Java SE, not Java ME

• No Swing, RMI, Naming, Management, etc. APIs

• Each application runs in its own process/own instance of DVM

• Linux kernel – version 2.6• Drivers, C/C++ Libraries, etc.• Generally exposed through Application Framework

Linux kernel

Libraries

Android Runtime

Application Framework

Java Apps

Drivers (display, camera, etc.)

SQLite, OpenGL ES, WebKit, SGL, SSL, Libc, Media Framework, etc.

DVM along with core libraries

Activity Manager, Content Provider, Telephony Manager, etc. (Java

classes)

At the center of the Oracle/Google lawsuit

Page 16: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 16

Android Development – What You Need• Java JDK

• www.oracle.com/technetwork/java/javase/downloads

• Android SDK• developer.android.com/sdk

• Eclipse IDE• www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/

indigosr1

• Android Eclipse Plugin• developer.android.com/sdk/eclipse-adt.html

• You don’t need a device• No additional tools are necessary for Windows Azure development

Page 17: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 17

Understanding Android Development• JDK

• Not just the Java Runtime Environment (JRE)• Android currently supports Java 5 and 6

• Android SDK Starter Package• What you originally download• Windows, Mac and Linux versions• Starter Package is not a full development environment

• Download components, emulators, tools, add-ons, etc.• Start android.bat (in the Starter Package)• Starts the Android SDK and Android Virtual Device (AVD) Manager• Use this UI to get the rest of the SDK and all the extras

• Eclipse IDE• Android Development Tools Plug-in for Eclipse• Installed via Eclipse’s Install New Software… option• Not required but highly recommended

Page 18: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 18

Emulator• You don’t have to have a device to develop/test Android apps

• Nothing beats the real thing for final testing• Most work by simple USB port connection

• Emulator(s) come with the Android SDK

Does require some device configuration

Page 19: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 19

Android Versions• You determine what versions to

support• By default…

• Applications support all versions• Applications support all device

types• Tablets• Big/small displays• Etc.

• Use the AndroidManifest to change these defaults

• WAT for Android libraries written to version 2.2

• Can probably be used with all versions > 2.0

• But not tested

Current distri-bution*

v1.5v1.6v2.1v2.2v2.3v3.0v3.1v3.2

*Per developer.android.com – Dec 2012

Page 20: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 20

Android Projects• Your application code in src

• Your Android components• Package name matters

• Only one app per package name per device

• Source code Android generates• Don’t touch!• R.java = constants tied to resources• Auto-generated class indexing all the resources of

your project

• Res = project resources• Graphics (for different size devices)• Layouts (XML form of the UI)• Labels (i.e. strings)• May also include menus, xml, media, etc.

• Manifest – foundation of the application• Describes app components• Android version support• And more

Page 21: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 21

Android Applications• Android applications are really a loose affiliation of components

• Android applications have no single entry point• Components defined in one “application” can be used by another

application

• Android applications are comprised of one or more of the following “building block” components:• Activities – “screens” that contain views (“widgets”)• Intents – “messages” between components• Services – think worker roles• Content Providers – think storage• Other “components”

• Components are specified in AndroidManifest.xmlDemo 1 – Hello Android

Page 22: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 22

Android Market• market.android.com

• Owned and operated by Google

• A place to sell/offer you Android applications• You need Google Checkout

• Not available in all countries• 30% fee goes to Android market• Fee to the mobile carriers who distribute and support the Android Market• Google Checkout may add an additional fee(s)

• There are other market places/sites (Amazon, AndAppStore, …)

• Unlike some mobile OS platforms…• You can install your apps directly onto devices through USB port• You can distribute your app as a download off your Web, FTP, etc. site

• Make your APK (Android Package) file available like any download • Make sure the Android APK MIME type is configured on your Web server

Page 23: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 23

More on Android• Intertech’s Complete Android course (4 day – virtual available)

• www.intertech.com

• Books (there are a ton – many out of date or poor)• The Busy Coder's Guide to Android Development • Android in Action (Manning)• Professional Android Application Development (Wrox)

• Web sites (there are a ton – here are some I found useful)• developer.android.com• www.anddev.org• androidcommunity.com• www.androidpolice.com• gorgando.com/blog/topics/technology/android_development/awesome-

android-tutorials-for-beginners

Page 24: Connecting Android to Windows Azure

An Intertech Course

WAT for Android

Setup

Page 25: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 25

Getting WAT for Android• Download WAT for Android from GitHub

• https://github.com/microsoft-dpe/wa-toolkit-android• You’ll need Git or Git plugin through Eclipse

• http://git-scm.com/download

• The download contains several Eclipse-ready projects• The projects contain

• Access control and storage API• Unit tests for same• Samples app for demonstration use• Docs

• Very minimal• Helps setup WAT for Android in Eclipse• See GettingStarted.docx in docs!

Page 26: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 26

Import the Projects into Eclipse• Minimally, import…

• The Storage for Android project• Access Control for Android project• The Storage for Android Sample

App

• Optionally, import …• ACS for Android Sample App• Unit test for all projects

• Usually requires some minor project fixes

• Fix project classpaths• Update the projects to point to

your Android SDK location• Reference the libraries correctly

Page 27: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 27

Cloud Ready Packages for Devices • Provides the authentication membership and ACS service packages

• Not necessary if you are planning on using direct access.

• Designed to make it easier for you to build mobile applications that leverage Windows Azure services.

• Download contains a Windows Azure service package that deploys to a Windows Azure account.

• Available in extra large to extra small VM size

• Available at: github.com/microsoft-dpe/wa-toolkit-cloudreadypackages

Page 28: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 28

Cloud Ready Package for Devices Setup• Create a new Hosted service (but don’t deploy yet)• Create and deploy a certificate to the new hosted service

• Cloud Ready package needs to communicate via HTTPS• Can be self-signed but then you get the warnings• Better if it is CA-signed (requires domain name/DNS routing)

• Change the CloudReady service configuration (.cscfg file)• Update storage location• Update cert thumbprint• See next page

• Deploy Hosted Service

DNSAzure.com

Page 29: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 29

CloudReady - ServiceConfiguration.Cloud.cscfg• Update storage account info• Update cert thumbprint

Page 30: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 30

CloudReady Test• Once deployed, you can test your service via browser• Go to https://<cloud ready service name>.cloudnet.app

• Membership service version shown here

Page 31: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 31

Test WAT for Android• With the Cloud Ready service of your choice service deployed…• …and with WAT for Android projects imported into Eclipse…• …you can now test WAT for Android in Eclipse (using an Emulator or

real device)• Open the Windows Azure for Android Sample App• Find and open the strings.xml file (in res/values)

Page 32: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 32

Configure WAT for Android Sample App• In the Android Resources editor…

• First change the toolkit_connection_type value to be one of following:• Direct – for direct access to your storage account• CloudReadySimple – to use CloudReady membership service• CloudReadyACS – to use CloudReady ACS service

Page 33: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 33

Configure WAT for Android Sample App Continued• For direct access, also change…

• direct_account_name• To your storage account name

• direct_access_key• To your storage account key

• For membership access, also change…

• cloud_ready_simple_proxy_service• To your proxy service URL

For ACS access, you need to setup even more string resources

Page 34: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 34

Run WAT for Android Sample App

Demo 2 – WAT Sample App

Page 35: Connecting Android to Windows Azure

An Intertech Course

WAT for Android

API

Page 36: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 36

WAT for Android API• Unfortunately, it is not very well packaged API

• .storageclient contains Storage API (both public and lower level classes )• This package also contains direct access auth API• .storageclient.wazservice contains proxy service auth API

• The access API is new and unseen• Direct access • Two forms of proxy server access APIs• Proxy form API descends from direct access form

• The storage access API largely mimics Windows Azure storage APIs• Knowledge of WA storage API is almost required given lack of documentation• Sample application helps• Sometimes you have to dig into the source code

Page 37: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 37

A Peek at the Direct Access Authentication APItry { CloudClientAccount cloudAccount = new CloudStorageAccount( new StorageCredentialsAccountAndKey(accountIdString, accountKeyString));

// to actually login and check that storage is available try getting a storage client cloudAccount.createCloudTableClient();} catch (Exception e) { Log.println(Log.ERROR, "Login Activity", "Failure in authentication");}

Page 38: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 38

A Peek at the Proxy Server Access Authentication API• WAZServiceAccount is a more specific type of CloudClientAccount

try { WAZServiceAccount cloudAccount = new WAZServiceAccount(

new WAZServiceUsernameAndPassword(usernameString, passwordString),new URI(proxyURLString);

// to check the login, but specific to WAZServiceAccount object cloudAccount = loginToWAZService();} catch (Exception e) { Log.println(Log.ERROR, "Login Activity", "Failure in authentication");}

// otherwise you can again try to get storage clienttry { … cloudAccount.createCloudTableClient();} catch (Exception e) { Log.println(Log.ERROR, "Login Activity", "Failure in authentication");}

Page 39: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 39

A Peek at Table Storage API• Getting all entities from a known table

try { CloudTableClient tableClient = cloudAccount.createCloudTableClient(); StorageCredentials tableCredentials = tableClient.getCredentials(); if (tableClient.doesTableExist(tableName)) {

// get all the rows from the database table Iterable<Map<String, Object>> entities = CloudTableObject.query(

tableClient.getEndpoint(),tableCredentials, tableName);

Iterator<Map<String, Object>> iterator = entities.iterator();while (iterator.hasNext()) {

Map<String, Object> entity = iterator.next();String part = entity.get(“PartitionKey”).toString());String key = entity.get(“RowKey”).toString());String xProp = entity.get(“x”).toString());String yProp = entity.get(“y”).toString());

} }} catch (Exception e) {…}

Page 40: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 40

A Peek at Table Storage API (continued)• Deleting an entity

try {CloudTableClient tableClient = cloudAccount.createCloudTableClient();StorageCredentials tableCredentials = tableClient.getCredentials();CloudTableObject<CloudTableEntity> tableObject =

new CloudTableObject<CloudTableEntity>(tableName,tableClient.getEndpoint(), tableCredentials);

tableObject.delete(partitionString,keyString);} catch (Exception e) {

Log.println(Log.ERROR, "SelectRow", "Problems deleting entity");e.printStackTrace();

}

Page 41: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 41

A Peek at Table Storage API (continued)• Inserting an entity

try {Map<String, Object> entity = new Hashtable<String, Object>();entity.put(“PartitionKey”, partitionString);entity.put(“RowKey”, keyString);entity.put(“x”, x); //property key and valueentity.put(“y”, y); //property key and valueCloudTableClient tableClient = cloudAccount.createCloudTableClient();

StorageCredentials tableCredentials = tableClient.getCredentials();if (tableClient.doesTableExist(tableName)) {

CloudTableObject.insert(tableClient.getEndpoint(),tableCredentials, tableName, entity);

}} catch (Exception e) {

Log.println(Log.ERROR, "AddRow","Problem adding row to the default table");e.printStackTrace();

}

Page 42: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 42

A Peek at Table Storage API (continued)• Some other operations

• Query

• Update

String filter = String.format("PartitionKey eq '%s' and RowKey eq '%s'",encodeValueForFilter(partitionKey), encodeValueForFilter(rowKey));

Iterable<Map<String, Object>> entities = CloudTableObject.query(tableClient.getEndpoint(), tableCredentials, tableName, filter);

Map<String, Object> entity = new Hashtable<String, Object>();for (EditText editText : getEditTexts()) { entity.put((String) editText.getTag(), editText.getText().toString());}CloudTableObject.update(tableClient.getEndpoint(), tableCredentials, tableName, entity);

Demo 3 – Simplified Access and Table Storage ExampleNot following Android or Azure best practices

Page 43: Connecting Android to Windows Azure

An Intertech Course

Wrap up

Page 44: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 44

Limitations and Future• Toolkit lacks documentation

• Other than setup guides, there is little or no documentation• But, at least the source code is provided to you• Sample app helps and it is much better than the first release

• No access to SQL Azure - Yet• Wade Wegner states updates to Windows Azure Toolkits for iOS and Android are coming…

• “so that they are in full parity with the Windows Azure Toolkit for Windows Phone”

• Not there yet• Worker role communication API• Service management API• Diagnostic API

• Improvements coming?• Better organization/structure• Simplifications• More examples - promised, but not there yet.

• Ample room for other 3rd parties to provide extensions• Marshaling/unmarshaling code for entities, messages, etc.• Async tasking• Etc.

Page 45: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 45

More on WAT for Android• Windows Azure Mobile

• www.windowsazure.com/en-us/home/scenarios/mobile/

• WAT for Android announcement page• blogs.msdn.com/b/windowsazure/archive/2011/08/31/now-available-windows-

azure-toolkit-for-android.aspx

• Wade Wegner’s Blog page and how-to• www.wadewegner.com/2011/08/windows-azure-toolkits-for-devices-now-with-

android/

• Wade Wegner Video on use of WAD for Android• blogs.msdn.com/b/zxue/archive/2011/11/21/developing-android-apps-using-

windows-azure-toolkit.aspx

• WAT for Windows Phone (good documentation on Cloud Ready packages)• watwp.codeplex.com/documentation

Page 46: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 46

An Intertech Course

Q & A

Page 47: Connecting Android to Windows Azure

Course Name

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 47

An Intertech Course

Thanks for coming!

Happy Holidays and see you “virtually” next month.

[email protected]/blog