SDK Android

Last updated March 30, 2021


The purpose of this manual is to provide all of the information necessary to install and use the tools in the apps developed for the Android platform.

This SDK is written in Java, it gathers device data (information and location) and sends it to ClearSale. The data gathered will be related solely to the device and is unrelated to the integrated app.

Geolocation data depends on permission granted by the device user. This means the app must request access to user location data (the SDK does not ask for permission). If the app does not request access or if the user denies permission the data will not be gathered.

SDK respects Apple's privacy policy in terms of gathering device data and the level of permission granted by the device user.


Package Installation

  • Gradle

The pod is available in a maven private repository, using it requires adding the following repository to the root gradle file:


maven {
        url ''
       name 'BehaviorAnalytics.SDK.Android'
       credentials {
       username "vstscs"
       password TOKEN_DE_ACESSO


A request for an access token must be sent to ClearSale.

  • Gradle

O pacote está disponível em um repositório maven privado, e para sua utilização é necessário adicionar ao arquivo gradle raiz:


maven {
        url ''
       name 'BehaviorAnalytics.SDK.Android'
       credentials {
       username "vstscs"
       password TOKEN_DE_ACESSO


É necessário solicitar o token de acesso junto à ClearSale.

Project Configuration

The following dependences must be used in the project: play-services-location, play-services-ads, gson. For this, add the following information to the dependencies section of the Gradle file.

dependencies {
    // Other project dependencies.
    // Required dependencies
    implementation ''
    api ''
    implementation 'sale.clear.behavior:sdk-behavior:4.0.0-rc.1'

    // Optional dependencies
    api ''

We recommend Gradle 6.6.1, Android Studio 4.1.rc.3 and plugin 4.1.rc.3

App permissions

Using SDK requires asking for the following permissions in the manifest file:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

Apps using Android version 26 or higher as the Target and that wish to capture geolocation data must not only add ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION to the manifest, but also ask for user permission to gather geolocation data, as per the Android recommendation.

Behavior Class


Behavior is the class responsible for data gathering.


This class has no public builders. The instance must be made using a static method.

Static Methods
Method name Description
Behavior.getInstance(String app) :Behavior

Obtain the Behavior class instance for an AppKey.

The AppKey (provided by ClearSale) must be given as a parameter.



Method name Description

generateSessionID() :String

Generates and returns a session identifier.

This method is to be used only if the app has no session value.

This value must be stored and sent to ClearSale at the moment of order integration.

collectDeviceInformation(String sessionID) :void

Gathers data on the device linked to the Session value.

SessionId, the session value must be provided as a parameter. This value must be stored and sent to ClearSale at the moment of order integration.

- If that SessionID has no unique value use). generateSessionId().
- The maximum size of SessionID is 128 characters.
- The minimum size of SessionID is 6 characters.

SessionIDAlreadyUsedException - launched when a given session value is used more than once.
InvalidSessionIdException - launched when sessionId value is out of range [6-128] or when null sessionId is passed.



There are two ways to initialize the SDK. This depends on the type of screen to be used. If it is an Activity screen, initialization must use the onCreate() method. If it is a Fragment screen, initialization must use the onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) method.

Note: In both cases (Activity or Fragment), if the stop() approach is not called within the onStop() method of one of the screens because it is a singleton, when start() is called on the next screen a CaptureWasStartedException exception will be launched.

All examples presume the existence of the following variables:

  • mBehavior, which represents the Behavior class instance. This may be replaced with ut1}Behavior.getInstance(contexto, CLEAR_SALE_APP).
  • String-type CLEAR_SALE_APPvariable type string, the value of which will be provided by ClearSale.

To start a call on a Fragment screen.
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                Bundle savedInstanceState) {
    // To obtain the Context in a Fragment.
    View rootView = inflater.inflate(R.layout.fragment_login, container, false);
    Context context = rootView.getContext();
    //CLEAR_SALE_APP is a value to be provided by ClearSale.
    mBehavior = Behavior.getInstance(mContext, CLEAR_SALE_APP);
    return rootView;

For an Activity screen
public void onCreate() {
    //CLEAR_SALE_APP is a value to be provided by ClearSale.
    mBehavior = Behavior.getInstance(this, CLEAR_SALE_APP);

To initiate capture:

To collect and send data to ClearSale you should use collectDeviceInformation(SESSION_ID) method inside onResume() method

    public void onResume() {
        try {
            //Only on the screens where the data gathered will be sent to ClearSale
            String sessionId = mBehavior.generateSessionID()
        catch (CaptureWasStartedException e) {
            //This indicates that the startCapture approach was called up previously and not 
            //the stopCapture() approach was called up in the onStop() approach.
            Log.e(LOG_TAG, e.getMessage());
        }catch (SessionIDAlreadyUsedException e) {
            //The same SessionID was used before.
            Log.e(LOG_TAG, e.getMessage());

To stop capturing:
public void onStop() {

User License

By downloading and using our SDK you are agreeing to the following license.

Copyright © 2021 ClearSale

All rights reserved. This license grants permission to use the software "as is". The software may not be modified or copied for any purpose. The Software is licensed as configured and with absolutely no expressed or implicit guarantee, including but not limited to marketing guarantees, suitability for specific purposes and non-violation of patented rights. Under no circumstances may the owners of the Copyright be held liable for damages, losses, basis for lawsuits due to contract or illegal acts or any other illegal means arising from the use of the Software or other actions related to this Software without the prior written authorization of the copyright holders.