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
Declare our SDK as a dependency by adding the following to your build.gradle file:
Copydependencies { compile "com.github.aloomaio.androidsdk:androidsdk:6.0.2" }
Declare Google Play Services (gcm) as a dependency:
Copydependencies { compile 'com.google.android.gms:play-services-gcm:9.4.0+' }
Step 2 – Add the necessary permissions to your app
The SDK requires permission to access the internet, and (optionally) to access the network state and Bluetooth state for event enrichment.
For internet access permissions, write:
Copy<uses-permission android:name="android.permission.INTERNET" />
and optionally, for network and bluetooth state, use:
Copy<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.BLUETOOTH" />
Step 3 – Initialize the SDK
Log in to your Alooma account and add an "iOS/Android App" input.
Give your input a label (name), and copy the generated token.
Initialize an SDK instance with your Alooma hostname and token from the previous step, i.e.:
CopymAPI = AloomaAPI.getInstance(context, "<YOUR_TOKEN>", "inputs.alooma.com", true)
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 theonDestroy
method of your main application activity:Copy@Override protected void onDestroy() { mAPI.flush(); super.onDestroy(); }
When you call
flush()
, the library attempts to send all unsent events. If you don’t callflush
, 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:
CopyAloomaAPI mAPI = AloomaAPI.getInstance(context, "inputs.alooma.com”); JSONObject props = new JSONObject(); props.put("email", "example@domain.com"); 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
Was this helpful?