Collecting Usage Statistics

Track key performance indicators (KPIs) such as device types, operating systems, and SDKs.


The SDK components automatically log some predefined events and metrics. You can also log custom-defined timers, events, and measurements.

To collect statistics, you need the Android Native Client SDK libraries, which are available as part of the SAP Mobile Platform Client SDK Installer. The Usage library ships in the form of separate artifcates, such as statically linked libraries and public header files.

If the server on which statistics are being collected uses a HANA database, the database must use a flexible schema.

Before you can use the Usage library, you must add associated artifacts to your project. You must also add dependent frameworks and configure your build settings. If you are working with an existing project rather than creating a new one, the steps may differ.


  1. Create a new Android project, or open an existing one.
  2. Set the package and versionName properties of the manifest tag in your project's androidManifest.xml file. For example:

    The Usage library reads these values and uses them as application ID and version number values.

    See published on non-SAP site in the Android Developer documentation for additional information about the manifest file.

  3. Copy the Usage.jar file to the libs folder of your project.
  4. To enable the Usage library to automatically upload the created logs, add these jar files from the SDK to the libs folder:
    • HttpConversation.jar
    • HttpConvAuthFlows.jar
    • SupportabilityFacade.jar
    • ClientLog.jar
  5. The Usage library also depends on SQLCipher, which is part of the installer package.
    1. Add these files to the libs folder:
      • sqlcipher.jar
    1. Add to the assets folder.
  6. Open AndroidManifest.xml, and add the following permissions:
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  7. Implement the necessary code.
    1. Initialize the Usage library:
      Usage(Context context, URL url, HttpConversationManager conversationManager);
      To encrypt the database, use this API call:
      Usage(Context context, URL url, HttpConversationManager conversationManager, String dataEncryptionKey)
    2. After initialization, you can start timers to measure certain events. This example measures the user session, when the activity comes to the foreground:
      protected void onResume() {
    3. Stop timing the user session if the activity goes to the background:
      protected void onPause() {
    4. To manage the timer instance, start and get a Timer object by calling:
      Timer makeTimer(String key)
    5. Stop and persist a timer:
      void stopTimer(Timer timer)
    6. To log an event, for example, when an item is added or a button is pressed, use the log method:
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      	Intent intent = new Intent(parent.getContext(), DetailsActivity.class);
      	intent.putExtra("DETAIL", description[position]);
      	Map<String, String> descriptionInfo = new HashMap<String, String>();
      	descriptionInfo.put("Main description", description[position]);
      	usage.log("Details View Called", descriptionInfo, "description list");