Introduction to Developing Android Apps With the Salesforce Mobile SDK

26
Introduction to Developing AndroidApps Using the Salesforce Mobile SDK Ryan Upton, Salesforce.com, Mobile Evangelist @ryanjupton
  • date post

    21-Oct-2014
  • Category

    Technology

  • view

    520
  • download

    3

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

Page 1: 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

Page 2: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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.

Page 3: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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.

???

Page 4: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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

Page 5: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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

Page 6: Introduction to Developing Android Apps With the Salesforce Mobile SDK

Simplicity

+ =

Page 7: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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.

Page 8: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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.

Page 9: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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.

Page 10: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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

Page 11: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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

Page 12: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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

Page 13: Introduction to Developing Android Apps With the Salesforce Mobile SDK

Demo

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

Page 14: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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.

Page 15: Introduction to Developing Android Apps With the Salesforce Mobile SDK
Page 16: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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);

}}

Page 17: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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);

}}

Page 18: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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);

}}

Page 19: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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) {

Page 20: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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);

}}

Page 21: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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);

}}

Page 22: Introduction to Developing Android Apps With the Salesforce Mobile SDK

Demo

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

Page 23: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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.

Page 24: Introduction to Developing Android Apps With the Salesforce Mobile SDK
Page 25: Introduction to Developing Android Apps With the Salesforce Mobile SDK

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

Page 26: Introduction to Developing Android Apps With the Salesforce Mobile SDK