Skip to Content
SAP Mobile Platform

SAP Precision Marketing Android SDK

This tutorial explains how to import the SAP Precision Marketing App Example into Eclipse. This sample app implements several common usage scenarios by providing working source code that interacts with the SPM Device API and displays returned data. This example is a helpful resource to learn basic SPM
concepts and can provide a working base to build your own application.

The App Example uses SPM Java API Kit (bundled with the app). Full source code and java docs for the API Kit are also provided with the download.

Prerequisites

Follow these steps to get the SDK and set up an SPM account:

  1. Sign up for a Free Trial account on SDN: http://scn.sap.com/docs/DOC-35829
  2. Once you have accepted the EULA you will receive your SPM account, developer and consumer id, your private key and a link where you can download the SDK.
  3. Update the developer key/secret in the SDK to use the ones you received in the previous step.

Install following on your system to work with the SAP Precision Marketing App Example for Android:

  • Android SDK Tools
  • Eclipse

If you have already set up Eclipse for Android development, then move to the next section.

To setup Eclipse perform the following steps:

  1. Download and install the Android SDK Tools for your system. Refer to: http://developer.android.com/sdk/index.html
  2. Download and install Eclipse. Refer to: http://www.eclipse.org/downloads/
  3. Install the Eclipse plugin for Android development. Refer to:http://developer.android.com/sdk/installing/installing-adt.html.
  4. After installing the Android SDK, open the Android SDK Manager and ensure that you download Android 4.0 (API 14) and Extras - Google Play Services (Rev 13 or later).

Import the App Example into an Eclipse Workspace

Import the App Example into an Eclipse workspace by following these steps:

1. Unzip the SPM Java API Kit

    Unzip the apikit-1.0.zip file (for example: on your desktop). Remember this location, as you will need to find it later.

2. reate a folder for an Eclipse workspace.
You can use any name you like. In this App Example, we use SAP_Precision_Marketing_Workspace.

3. Start Eclipse.
Select the workspace you created above. In the Workspace Launcher that appears after Eclipse is started, choose Browse... to specify the path to the workspace folder, and then choose OK.


4. Import SAP Precision Marketing Android Example into Workspace.

5. Choose File --> Import. The Import dialog box displays.

6. Under Android, choose Existing Android Code into Workspace and then choose Next.


7. The Import Projects dialog box displays. Use the Browse... button to select the location of the unzipped app example (from step 1 above). Ensure that Copy Projects into Workspace is checked and then choose the Finish button. Note that after clicking Finish, Eclipse will report errors in the project until the remainder of the steps in this section are completed.


8. Import Google Play Services Lib into the Eclipse Workspace.The Google Play Service lib contains additional functionality beside the standard Android
platform. It is part of the Android SDK tools. You must import this library so that the app example has access to the Google Maps V2 functionality.
To begin, in Eclipse, choose File --> Import. The Import dialog appears as displayed below. Under Android, choose Existing Android Code into Workspace and then choose Next.



The Import Projects dialog box displays. Use the Browse... button to select the location of the Google Play Service lib (it is located with the Android SDK tools: <AndroidHome>/extras/google/google_play_services/libproject). Ensure that Copy Projects into Workspace is unchecked, and then choose Finish.


9. Add Google Play Services Lib to the App Example .To add the Google Play Services Lib, right-click on MainActivity in the Eclipse Project
Explorer and then select Properties. The Properties dialog box displays. Choose Android from the list on the left to view the android properties:



In the Library section above, highlight the existing entry with the red X and choose the Remove button. The Library section will now be empty.Next, choose the Add... button in the Properties dialog box above. The Project Selection dialog box appears, as displayed below. Highlight google-play-services_lib and choose OK.



The project properties dialog box displays again. To display the Google Play Services library in the Library section, choose OK.


Google Maps Key

The SAP Precision Marketing App Example  for Android uses Google Maps V2, which requires a key. To obtain a key, follow the instructions here.

Once you have a key, open the AndroidManifest.xml, locate the XML fragment below, and replace your-key-here your Google Maps V2 key.


<meta-data android:name="com.google.android.maps.v2.API_KEY"android:value="your-key-here" />


Device API Developer ID and Secret

The SAP Precision Marketing App Example  for Android uses the SAP Precision Marketing Device API. To configure access to this API in the App Example, open ConnectionInitializer.java and replace your-developer-id-here and your-developer-secret-here with your developer id and secret.


private static String DEVELOPERID = "your-developer-id-here";

private static String DEVELOPERSECRET = "your-developer-secret-here";

Deploying to Android Device or Emulator

Once you have completed all the above sections, the SAP Precision Marketing App Example for Android is ready to deploy.

If you are using a real device:

  • Android 4.0 or later must be running

If you are using an emulator:

  • Ensure the target is set to Android 4.0 (API 14)