SlideShare a Scribd company logo
Introduction to Developing Android™
Apps
Using the Salesforce Mobile SDK
Ryan Upton, Salesforce.com, Mobile Evangelist
@ryanjupton
Safe Harbor
Safe 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.
Complexity
We 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
Infrastructure Application
Services
Services

Operations
Services

Platform
Services

Touch
Services

Social
Services

Network

Security/Sharing

Authentication

Globalization

Native iOS SDK

Feeds

Storage

Integration

Availability

APIs

Native Android SDK

Profiles

Operating System

Customization

Monitoring

Security

HTML5

Status updates

Database

Web Services

Patch Management

Analytics

Xcode wizards

Groups

App Server

Multi-Language

Upgrades

Search

PIN code support

File sharing

Web Server

Workflow

Backup

Identity

Custom APEX REST

Approvals

Data Center

NOC

Geo-location Mobile

Messenger

Disaster Recovery

Troubleshooting

APIs

Presence

Your
Innovative
App
Salesforce.com Mobile SDK for Android
The Salesforce.com Mobile SDK for Android gives developers the
power to create sophisticated mobile apps that leverage the power
of the Force.com platform.
OAuth2
Secure authentication and refresh token
management

API Wrappers
Interact with Salesforce REST APIs with
popular mobile platform languages

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

Secure Offline Storage
Store business data on a device with enterpriseclass encryption

Push Notifications
Dispatch real-time alerts directly to mobile
devices
Simplicity

+

=
Getting the SDK
There 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.
Forcedroid
Forcedroid 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 Apps
After 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.
OAuth
An open protocol to allow secure authorization in a simple
and standard method from web, mobile and desktop
applications.
▪ Oauth simplifies working with protected data.
Sends App Credentials

▪ Prevents password
anti-pattern.
▪ Think valet key.

Tokens sent to callback

Remote
Application

API call with access token
Data

Maintain session with
refresh token

User
logs in

Salesforce
Platform
Force.com REST API
The 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.
1. Authenticate
login.salesforce.com

Mobile
Application

2. Access API
/services/data/query?
SELECT ID FROM ACCOUNT

3. Get JSON or XML
{“sObject”: “Account”,
“id” : “oax02fdr756aFdad”}

Salesforce
Platform
Native Classes
▪ SalesforceSDKManager
▪ RestClient
▪ ClientManager
▪ LoginActivity
▪ SalesforceActivity
▪ PasswordManager
▪ AccountWatcher
Demo

▪ Create an app
▪ Configure Connected App settings
▪ Review template code
Data Access
It’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.
Introduction to Developing Android Apps With the Salesforce Mobile SDK
Read data
private 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() {
@Override
public 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 data
private 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() {
@Override
public 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 data
private 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() {
@Override
public 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 data
public 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),
fields);
client.sendAsync(restRequest, new AsyncRequestCallback() {
@Override
public void onSuccess(RestRequest request, RestResponse result) {
try {
DetailActivity.this.finish();
} catch (Exception e) {

”Contact", id,
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() {
@Override
public 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() {
@Override
public 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
Recap
We’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.
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
Introduction to Developing Android Apps With the Salesforce Mobile SDK

More Related Content

Introduction to Developing Android Apps With the Salesforce Mobile SDK

  • 1. Introduction to Developing Android™ Apps Using the Salesforce Mobile SDK Ryan Upton, Salesforce.com, Mobile Evangelist @ryanjupton
  • 2. Safe Harbor Safe 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.
  • 3. Complexity We 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. ???
  • 4. The Force.com Platform Infrastructure Application Services Services Operations Services Platform Services Touch Services Social Services Network Security/Sharing Authentication Globalization Native iOS SDK Feeds Storage Integration Availability APIs Native Android SDK Profiles Operating System Customization Monitoring Security HTML5 Status updates Database Web Services Patch Management Analytics Xcode wizards Groups App Server Multi-Language Upgrades Search PIN code support File sharing Web Server Workflow Backup Identity Custom APEX REST Approvals Data Center NOC Geo-location Mobile Messenger Disaster Recovery Troubleshooting APIs Presence Your Innovative App
  • 5. Salesforce.com Mobile SDK for Android The Salesforce.com Mobile SDK for Android gives developers the power to create sophisticated mobile apps that leverage the power of the Force.com platform. OAuth2 Secure authentication and refresh token management API Wrappers Interact with Salesforce REST APIs with popular mobile platform languages App Container Embed HTML5 apps inside a container to access powerful native device functionality Secure Offline Storage Store business data on a device with enterpriseclass encryption Push Notifications Dispatch real-time alerts directly to mobile devices
  • 7. Getting the SDK There 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.
  • 8. Forcedroid Forcedroid 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.
  • 9. Building Native Apps After 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.
  • 10. OAuth An open protocol to allow secure authorization in a simple and standard method from web, mobile and desktop applications. ▪ Oauth simplifies working with protected data. Sends App Credentials ▪ Prevents password anti-pattern. ▪ Think valet key. Tokens sent to callback Remote Application API call with access token Data Maintain session with refresh token User logs in Salesforce Platform
  • 11. Force.com REST API The 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. 1. Authenticate login.salesforce.com Mobile Application 2. Access API /services/data/query? SELECT ID FROM ACCOUNT 3. Get JSON or XML {“sObject”: “Account”, “id” : “oax02fdr756aFdad”} Salesforce Platform
  • 12. Native Classes ▪ SalesforceSDKManager ▪ RestClient ▪ ClientManager ▪ LoginActivity ▪ SalesforceActivity ▪ PasswordManager ▪ AccountWatcher
  • 13. Demo ▪ Create an app ▪ Configure Connected App settings ▪ Review template code
  • 14. Data Access It’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.
  • 16. Read data private 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() { @Override public 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); } }
  • 17. Delete data private 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() { @Override public 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); } }
  • 18. Create data private 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() { @Override public 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); } }
  • 19. Update data public 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), fields); client.sendAsync(restRequest, new AsyncRequestCallback() { @Override public void onSuccess(RestRequest request, RestResponse result) { try { DetailActivity.this.finish(); } catch (Exception e) { ”Contact", id,
  • 20. 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() { @Override public 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); } }
  • 21. 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() { @Override public 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); } }
  • 22. Demo ▪ Modify template app ▪ Use REST API to query records ▪ Use REST API to update record ▪ Use REST API to call Apex REST
  • 23. Recap We’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.
  • 25. 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