Introduction to Developing Android Apps With the Salesforce Mobile SDK

Post on 21-Oct-2014

525 views 3 download

Tags:

description

This session will show mobile developers how to build enterprise Android applications using our new Salesforce Mobile SDK. Not only will users be shown how to use the new features and functions of the SDK but we'll also dive into best practices for building mobile APIs focussed on enterprise business applications.

Transcript of Introduction to Developing Android Apps With the Salesforce Mobile SDK

Introduction to Developing Android™ AppsUsing the Salesforce Mobile SDK

Ryan Upton, Salesforce.com, Mobile Evangelist@ryanjupton

Safe HarborSafe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.

ComplexityWe know how to make consumer mobile apps.But how do we deal with new complexities of enterprise mobile apps?

▪ Authentication & authorization.▪ Ubiquitous data access.▪ Data protection. ▪ Governance.

???

The Force.com Platform

InfrastructureServices

NetworkStorage

Operating SystemDatabase

App ServerWeb ServerData Center

Disaster Recovery

OperationsServices

AuthenticationAvailabilityMonitoring

Patch ManagementUpgradesBackup

NOCTroubleshooting

Your Innovative

AppApplicationServices

Security/SharingIntegration

CustomizationWeb Services

Multi-LanguageWorkflow

TouchServices

Native iOS SDKNative Android SDK

HTML5Xcode wizards

PIN code supportCustom APEX RESTGeo-location Mobile

APIs

SocialServices

FeedsProfiles

Status updatesGroups

File sharingApprovalsMessengerPresence

PlatformServices

GlobalizationAPIs

SecurityAnalyticsSearchIdentity

Salesforce.com Mobile SDK for AndroidThe Salesforce.com Mobile SDK for Android gives developers the power to create sophisticated mobile apps that leverage the power of the Force.com platform.

API WrappersInteract with Salesforce REST APIs with popular mobile platform languages

Secure Offline StorageStore business data on a device with enterprise-class encryption

Push NotificationsDispatch real-time alerts directly to mobile devices

OAuth2Secure authentication and refresh token management

App ContainerEmbed HTML5 apps inside a container to access powerful native device functionality

Simplicity

+ =

Getting the SDKThere are two ways to get the Salesforce Mobile SDK for Android.

▪ Download the SDK• git clone https://github.com/forcedotcom/SalesforceMobileSDK-Android.git

▪ Forcedroid• Install Node.js and NPM.• Use the forcedroid package to install SDK globally or locally.

ForcedroidForcedroid provides the quickest, easiest route to Android development.

▪ Simple command line lets you quickly create template apps for• Native applications.• Hybrid applications (local and remote).• Including additional libraries.

Building Native AppsAfter running forcedroid to create a native application you will have a template for modifying your app.This template links in classes and configures services for managing▪ OAuth login flow.▪ REST API wrappers and REST client management.▪ Handling logout and OAuth credential management.

OAuthAn open protocol to allow secure authorization in a simple and standard method from web, mobile and desktop applications.▪ Oauth simplifies working with protected data.▪ Prevents passwordanti-pattern.▪ Think valet key.

RemoteApplication

SalesforcePlatform

Sends App Credentials

Tokens sent to callback

API call with access token

Data

Maintain session withrefresh token

User logs in

Force.com REST APIThe Force.com REST API lets you integrate with Force.com applications using simple HTTP methods, in either XML or JSON formats, making this an ideal API for developing mobile applications or external clients.

MobileApplication

SalesforcePlatform

login.salesforce.com

1. Authenticate

/services/data/query?SELECT ID FROM ACCOUNT

2. Access API

{“sObject”: “Account”,“id” : “oax02fdr756aFdad”}

3. Get JSON or XML

Native Classes▪ SalesforceSDKManager▪ RestClient▪ ClientManager▪ LoginActivity▪ SalesforceActivity▪ PasswordManager▪ AccountWatcher

Demo

▪ Create an app▪ Configure Connected App settings▪ Review template code

Data AccessIt’s important to understand the structure, format and size of data prior to running REST queries.

▪ You will need to know the JSON structure, content and amount of data before building queries.

▪ Workbench is an excellent tool for testing SOQL queries and analyzing data.

Read dataprivate void sendRequest() throws UnsupportedEncodingException {

String SOQL = “SELECT NAME FROM CONTACT”;RestRequest restRequest = RestRequest.getRequestForQuery(getString(R.string.api_version), soql);

client.sendAsync(restRequest, new AsyncRequestCallback() {@Overridepublic void onSuccess(RestRequest request, RestResponse result) {

try {JSONArray records = result.asJSONObject().getJSONArray("records");for (int i = 0; i < records.length(); i++) {

listAdapter.add(records.getJSONObject(i).getString("Name"));}

} catch (Exception e) {onError(e);

}}

Delete dataprivate void sendRequest() throws UnsupportedEncodingException {

String SOQL = “SELECT NAME FROM CONTACT”;RestRequest restRequest = RestRequest.getRequestForQuery(getString(R.string.api_version), soql);

client.sendAsync(restRequest, new AsyncRequestCallback() {@Overridepublic void onSuccess(RestRequest request, RestResponse result) {

try {JSONArray records = result.asJSONObject().getJSONArray("records");for (int i = 0; i < records.length(); i++) {

listAdapter.add(records.getJSONObject(i).getString("Name"));}

} catch (Exception e) {onError(e);

}}

Create dataprivate void sendRequest() throws UnsupportedEncodingException {

String SOQL = “SELECT NAME FROM CONTACT”;RestRequest restRequest = RestRequest.getRequestForQuery(getString(R.string.api_version), soql);

client.sendAsync(restRequest, new AsyncRequestCallback() {@Overridepublic void onSuccess(RestRequest request, RestResponse result) {

try {JSONArray records = result.asJSONObject().getJSONArray("records");for (int i = 0; i < records.length(); i++) {

listAdapter.add(records.getJSONObject(i).getString("Name"));}

} catch (Exception e) {onError(e);

}}

Update datapublic void onUpdateClick(View v) {

Map<String, Object> fields = new HashMap<String, Object>();fields.put("Name", nameField.getText().toString());fields.put(”Email", emailField.getText().toString());fields.put(”Phone", phoneField.getText().toString());RestRequest restRequest;restRequest = RestRequest.getRequestForUpdate(getString(R.string.api_version), ”Contact", id,

fields);client.sendAsync(restRequest, new AsyncRequestCallback() {

@Overridepublic void onSuccess(RestRequest request, RestResponse result) {

try {DetailActivity.this.finish();

} catch (Exception e) {

What about Apex REST?public void onRestQuery(View v) {

String url = “/services/apexrest/myRESTservice”;

restRequest = new RestRequest(RestMethod.GET, url, null);

client.sendAsync(restRequest, new AsyncRequestCallback() {

@Overridepublic void onSuccess(RestRequest request, RestResponse result) {

try {JSONArray records = result.asJSONArray();for (int i = 0; i < records.length(); i++) {

listAdapter.add(records.getString(i));}

} catch (Exception e) {onError(e);

}}

What about meta data?public void onGetMetadataClick(View v) {

String objectType = ((EditText) findViewById(R.id.metadata_object_type_text)).getText().toString();restRequest = RestRequest.getRequestForMetaData(getString(R.string.api_version), objectType);client.sendAsync(restRequest, new AsyncRequestCallback() {

@Overridepublic void onSuccess(RestRequest request, RestResponse result) {

try {JSONArray records = result.asJSONObject().getJSONArray("records");for (int i = 0; i < records.length(); i++) {

listAdapter.add(records.getJSONObject(i).getString("Name"));}

} catch (Exception e) {onError(e);

}}

Demo

▪ Modify template app▪ Use REST API to query records▪ Use REST API to update record▪ Use REST API to call Apex REST

RecapWe’ve covered a number of things in this session.Specifically we’ve learned:

▪ The benefits of the Force.com platform and▪ Salesforce.com Mobile SDK for Android.▪ How to create an Android application.▪ How to create a connected application.▪ Using the REST API to CRUD our data.▪ Using the REST API to call Apex REST.

We want to hear from YOU!

Please take a moment to complete our session survey

Surveys can be found in the “My Agenda” portion of the Dreamforce app