Download (WAT) for Android

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Connecting Android to Windows Azure
Windows Azure UG
December 2012
Monthly Meeting
An Intertech Course
Course Name
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 code
will be made available through azureug.net
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 2
Course Name
Agenda
•
•
•
What is the Windows Azure Toolkit for Android
A quick Android tutorial
Setup
•
•
•
•
Building an Azure accessing Android application
Sample the WAT for Android API
•
•
•
•
•
Learn how to get & setup the WAT for Android
See how to setup the Cloud Ready Packages for Devices
Authentication
Storage Access
Witness some demos
Limitations & More Info
Q&A
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 3
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 4
Windows Azure Toolkit for Android
Basics
An Intertech Course
Course Name
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)
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 6
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 7
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 8
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 9
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 10
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 11
Course Name
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)
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 12
Android Development
Tutorial
An Intertech Course
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 14
Course Name
At the center of
the Oracle/Google
lawsuit
Android Architecture
•
Write applications in Java
•
•
•
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
•
•
•
Java Apps
Application Framework
•
•
•
Java code is compiled to bytecode (.class)…
…then into .dex (Dalvik executable) files run by DVM
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 15
Application Framework
Activity Manager, Content
Provider, Telephony Manager,
etc. (Java classes)
Android Runtime
DVM along with core libraries
Libraries
SQLite, OpenGL ES, WebKit,
SGL, SSL, Libc, Media
Framework, etc.
Linux kernel
Drivers (display, camera, etc.)
Course Name
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-eedevelopers/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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 16
Course Name
Understanding Android Development
•
JDK
•
•
•
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.
•
•
•
•
Not just the Java Runtime Environment (JRE)
Android currently supports Java 5 and 6
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 17
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 18
Does require some
device configuration
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 19
Current distribution*
v1.5
v1.6
v2.1
v2.2
v2.3
v3.0
v3.1
v3.2
*Per developer.android.com – Dec 2012
Course Name
Android Projects
•
Your application code in src
•
•
Your Android components
Package name matters
•
•
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
•
•
•
•
•
Only one app per package name per device
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
Copyright ©•Intertech,
• www.Intertech.com • 800-866-9884
AndInc.
more
Slide 20
Course Name
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.xml
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 21
Demo 1 – Hello Android
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 22
Course Name
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/awesomeandroid-tutorials-for-beginners
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 23
WAT for Android
Setup
An Intertech Course
Course Name
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!
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 25
Course Name
Import the Projects into Eclipse
•
Minimally, import…
•
•
•
•
Optionally, import …
•
•
•
The Storage for Android project
Access Control for Android project
The Storage for Android Sample
App
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 26
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 27
Course Name
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
DNSAzure.com
• 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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 28
Course Name
CloudReady - ServiceConfiguration.Cloud.cscfg
• Update storage account info
• Update cert thumbprint
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 29
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 30
Course Name
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)
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 31
Course Name
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 32
Course Name
Configure WAT for Android Sample App Continued
•
For direct access, also change…
•
direct_account_name
• To your storage account name
•
direct_access_key
•
For membership access, also
change…
•
cloud_ready_simple_proxy_service
• To your proxy service URL
• To your storage account key
For ACS access, you need to setup even more string resource
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 33
Course Name
Run WAT for Android Sample App
Demo 2 – WAT Sample App
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 34
WAT for Android
API
An Intertech Course
Course Name
WAT for Android API
•
Unfortunately, it is not very well packaged API
•
•
•
•
The access API is new and unseen
•
•
•
•
.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
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 36
Course Name
A Peek at the Direct Access Authentication API
try {
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");
}
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 37
Course Name
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 client
try {
…
cloudAccount.createCloudTableClient();
} catch (Exception e) {
Log.println(Log.ERROR, "Login Activity", "Failure in authentication");
}
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 38
Course Name
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) {…}
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 39
Course Name
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();
}
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 40
Course Name
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 value
entity.put(“y”, y); //property key and value
CloudTableClient 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();
}
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 41
Course Name
A Peek at Table Storage API (continued)
• Some other operations
• Query
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);
• Update
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
Not following Android or Azure best practices
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 42
Wrap up
An Intertech Course
Course Name
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…
•
•
Not there yet
•
•
•
•
Worker role communication API
Service management API
Diagnostic API
Improvements coming?
•
•
•
•
“so that they are in full parity with the Windows Azure Toolkit for Windows Phone”
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
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 44
• Etc.
Course Name
More on WAT for Android
•
Windows Azure Mobile
•
•
WAT for Android announcement page
•
•
www.wadewegner.com/2011/08/windows-azure-toolkits-for-devices-now-withandroid/
Wade Wegner Video on use of WAD for Android
•
•
blogs.msdn.com/b/windowsazure/archive/2011/08/31/now-available-windowsazure-toolkit-for-android.aspx
Wade Wegner’s Blog page and how-to
•
•
www.windowsazure.com/en-us/home/scenarios/mobile/
blogs.msdn.com/b/zxue/archive/2011/11/21/developing-android-apps-usingwindows-azure-toolkit.aspx
WAT for Windows Phone (good documentation on Cloud Ready packages)
•
watwp.codeplex.com/documentation
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 45
Course Name
Q&A
An
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 46
Intertech Course
Thanks for coming!
Course Name
Happy Holidays and see you “virtually” next
month.
An
[email protected]
www.intertech.com/blog
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 47
Intertech Course