Android SDK Integration

Integrating with the Alooma Android SDK (hereafter, "the SDK") is simple and straightforward.

Step 1 – Add our SDK and prerequisites to your app as dependencies
  1. Declare our SDK as a dependency by adding the following to your build.gradle file:

    dependencies { 
      compile "com.github.aloomaio.androidsdk:androidsdk:6.0.2"
  2. Declare Google Play Services (gcm) as a dependency:

    dependencies { 
      compile ''
Step 2 – Add the necessary permissions to your app
  1. The SDK requires permission to access the internet, and (optionally) to access the network state and Bluetooth state for event enrichment.

  2. For internet access permissions, write:

    <uses-permission android:name="android.permission.INTERNET" /> 

    and optionally, for network and bluetooth state, use:

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
Step 3 – Initialize the SDK
  1. Log in to your Alooma account and add an "iOS/Android App" input.

  2. Give your input a label (name), and copy the generated token.

  3. Initialize an SDK instance with your Alooma hostname and token from the previous step, i.e.:

    mAPI = AloomaAPI.getInstance(context, "<YOUR_TOKEN>", 
                                "", true)
  4. To preserve battery life and customer bandwidth, the Alooma SDK doesn’t send recorded events immediately as they occur. Instead, it sends batches to the Alooma server periodically while your application is running. This means when your application shuts down, you need to inform the library to send any unsent events. Do this by calling AloomaAPI.flush() in the onDestroy method of your main application activity:

    protected void onDestroy() {
  5. When you call flush(), the library attempts to send all unsent events. If you don’t call flush, the events will be sent the next time the application is launched (don’t worry, the events will reflect the correct timestamp!).

You're done integrating the Alooma Android SDK into your app - now we’ll cover how to send app events to Alooma.

Step 4 - Sending events to Alooma

Send events that originate in your app can by using the track() method of the SDK.

For example, here's the short code used to send an event about a log in which contains the username and e-mail address of a user, using the token from step 2:

AloomaAPI mAPI = AloomaAPI.getInstance(context, "”);

JSONObject props = new JSONObject(); 
props.put("email", ""); 
props.put("username", "davidgreen1"); 
mAPI.track("User Login", props);

Each of these calls will create an event that will be sent to Alooma. learn more about the properties set by default on these events. Enjoy!

Search results

    No results found