SDK Android

Last updated: April 30th, 2024

Introduction

The purpose of this guide is to provide all the necessary information for installing and using the tool in applications developed for the Android platform.

This SDK collects and send device data (informations and locations) to ClearSale. All the information collected are device related data only, without regard to the integrated application.

Geolocation information depends on the permission granted by the user device, in this case is necessary that the application requests the access of the user location information (the SDK doesn't requests permission). If the application doesn't request the access or the user doesn't grant permission, for location, the GeoLocation information will not be captured.

SDK respects Google privacy policy for the device data capture and the permission level granted by the user (device user).

Checksum

Package Digest
sdk-behavior SHA256: 438240202C4248D0201149F376C5D2C776B81AE9F616317F07F67185F90BB997

To verify the dependency checksum in Gradle 6.2 or above, follow the instructions in this link: Dependency Verification

Checksum

Package Digest
sdk-behavior SHA256: AFE7DABDA5A1F7DCB2CC8A2264B62848E0112BBD045106F900F51851125AFB80

To verify the dependency checksum in Gradle 7.0 or above, follow the instructions in this link: Dependency Verification

Checksum

Package Digest
sdk-behavior SHA256: ECFFEECFE8A48793A5FAA4DC34E70009121267767B64EA7F44D2507EA734FE95

To verify the dependency checksum in Gradle 7.0 or above, follow the instructions in this link: Dependency Verification

Checksum

Package Digest
sdk-behavior SHA256: ABCCC91058E7005BC7B47A3A242E77575B0086224D18E9C75E85B0AE0ED1C54D

To verify the dependency checksum in Gradle 7.0 or above, follow the instructions in this link: Dependency Verification

Checksum

Package Digest
sdk-behavior SHA256: F67C436798EFAB2C50446090B39101C75217D724B654713AA8758CF498B51687

To verify the dependency checksum in Gradle 7.0 or above, follow the instructions in this link: Dependency Verification

Version Upgrade

To perform the version upgrade from 3.x.x to 5.6.6, follow this steps:

  1. Remove the 'com.google.code.gson:gson' dependency if it's not used in your project
  2. Replace the play-services-ads plugin with play-services-ads-identifier:18.0.1 plugin
  3. Update play-services-location plugin version to 19.0.1

To perform the version upgrade from 3.x.x to 5.6.7+, follow this steps:

  1. Remove the 'com.google.code.gson:gson' dependency if it's not used in your project
  2. Replace the play-services-ads plugin with play-services-ads-identifier:18.0.1 plugin
  3. Update play-services-location plugin version to 21.0.1

New Installation

Package Installation

  • Gradle (We recommend the use of Gradle 7.0.2 or above)

The package is available in a private repository, and for its use is necessaryto add the following repository to the root file:

maven {
    url 'https://pkgs.dev.azure.com/CS-PublicPackages/Behavior/_packaging/BehaviorAnalytics.SDK/maven/v1'
    name 'BehaviorAnalytics.SDK.Android'
}

  • Gradle (We recommend the use of Gradle 6.2 or above)

The package is available in a private repository, and for its use is necessaryto add the following repository to the root file:

maven {
    url 'https://pkgs.dev.azure.com/CS-PublicPackages/Behavior/_packaging/BehaviorAnalytics.SDK/maven/v1'
    name 'BehaviorAnalytics.SDK.Android'
}

Project Configuration

You must use the following dependencies in your project: play-services-location, play-services-ads-identifier. To do this, add the following information to your project's Gradle file, in the dependencies section.

dependencies {
    // Other dependencies of your project.
    //...
    // Required dependencies:
    implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
    implementation 'sale.clear.behavior:sdk-behavior: 5.6.7'
    api 'com.google.android.gms:play-services-location:21.0.1'
 }
dependencies {
    // Other dependencies of your project.
    //...
    // Required dependencies:
    implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
    implementation 'sale.clear.behavior:sdk-behavior: 6.0.0'
    api 'com.google.android.gms:play-services-location:21.0.1'
 }

dependencies {
    // Other dependencies of your project.
    //...
    // Required dependencies:
    implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
    implementation 'sale.clear.behavior:sdk-behavior: 6.0.8'
    api 'com.google.android.gms:play-services-location:21.0.1'
 }

The dependency 'com.google.android.gms:play-services-ads-identifier:18.0.1' is used to obtain information about the device's advertising identifier.

On the other hand, the dependency 'com.google.android.gms:play-services-location:21.0.1' should be used whenever it is necessary to collect geolocation information from the device.

Proguard

If you're using Proguard, include this rule

-keep class sale.clear.behavior.** { *; }

Application Permissions

To use the SDK is necessary to request some Permissions in the manifest file, they are:

<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"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

For applications that use Android version 26 or above as Target, and wishes to capture geolocation information, it's necessary, in addition to adding the ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions to the manifest, to request permission from the user to collect geolocation data, following this Android recommendation.


Note: For applications that uses version 33 (Android 13) or above as Target be able to capture information regarding advertisingID, it will be necessary to include the permission below:

<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

Project Configuration

You must use the following dependencies in your project: play-services-location, play-services-ads-identifier. To do this, add the following information to your project's Gradle file, in the dependencies section.

dependencies {
    // Other dependencies of your project.
    //...
    // Required dependencies:
    implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
    implementation 'sale.clear.behavior:sdk-behavior:5.6.6'
    api 'com.google.android.gms:play-services-location:19.0.1'
 }

The dependency 'com.google.android.gms:play-services-ads-identifier:18.0.1' is used to obtain information about the device's advertising identifier.

On the other hand, the dependency 'com.google.android.gms:play-services-location:19.0.1' should be used whenever it is necessary to collect geolocation information from the device.

Proguard

If you're using Proguard, include this rule

-keep class sale.clear.behavior.** { *; }

Application Permissions

To use the SDK is necessary to request some Permissions in the manifest file, they are:

<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"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

For applications that use Android version 26 or above as Target, and wishes to capture geolocation information, it's necessary, in addition to adding the ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions to the manifest, to request permission from the user to collect geolocation data, following this Android recommendation.


Note: For applications that uses version 33 (Android 13) or above as Target be able to capture information regarding advertisingID, it will be necessary to include the permission below:

<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

Project Configuration

You must use the following dependencies in your project: play-services-location, play-services-ads-identifier. To do this, add the following information to your project's Gradle file, in the dependencies section.

dependencies {
    // Other dependencies of your project.
    //...
    // Required dependencies:
    implementation 'com.google.android.gms:play-services-ads:18.3.0'
    api 'com.google.code.gson:gson:2.8.6'
    implementation 'sale.clear.behavior:sdk-behavior:3.0.2'

    // Optative dependencies:
    api 'com.google.android.gms:play-services-location:17.0.0'
 }

The optative dependency 'com.google.android.gms:play-services-location:17.0.0' must be used everytime that is necessary to collect geolocation information.

Application Permissions

To use the SDK is necessary to request some Permissions in the manifest file, they are:

<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"/> 

For applications that use Android version 26 or above as Target, and wishes to capture geolocation information, it's necessary, in addition to adding the ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions to the manifest, to request permission from the user to collect geolocation data, following this Android recommendation.


Note: For applications that uses version 33 (Android 13) or above as Target be able to capture information regarding advertisingID, it will be necessary to include the permission below:

<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

Play Store Privacy

If the user has consent with the geolocation and application list collection, the methods allowGeoLocation() and allowAppList() must be called, before the start() method, as in the example below:


@Override
public void onResume() {
    super.onResume();
    try {
        mBehavior.blockGeoLocation(); // Blocks the geolocation capture
        mBehavior.blockAppList(); //Blocks the capture of installed apps information on the device
        mBehavior.start(); //Information capture initialization
        
        String sessionId = mBehavior.generateSessionID()

        //Only in the screens that is desired to sent the collected data to ClearSale
        mBehavior.collectDeviceInformation(sessionId); //Prefereable after some time of user interaction.
    }
    catch (CaptureWasStartedException e) {
        //This error occurs when the method start() was called more than once without using stop() method.
        //Each capture (that starts with the start() method) needs to be closed (witch the stop() method call)
    }
}

Play Store Privacy

If the user has consent with the geolocation and application list collection, the methods allowGeoLocation() and allowAppList() must be called, before the start() method, as in the example below:


@Override
public void onResume() {
    super.onResume();
    try {
        mBehavior.allowGeoLocation(); //Enables geolocation capture
        mBehavior.allowAppList(); //Enables the capture of installed apps information on the device
        mBehavior.start(); //Information capture initialization
        
        String sessionId = mBehavior.generateSessionID()

        //Only in the screens that is desired to sent the collected data to ClearSale
        mBehavior.collectDeviceInformation(sessionId); //Prefereable after some time of user interaction.
    }
    catch (CaptureWasStartedException e) {
        //This error occurs when the method start() was called more than once without using stop() method.
        //Each capture (that starts with the start() method) needs to be closed (witch the stop() method call)
    }
}

Behavior Class

Description

Behavior is the class responsible to collect the informations.

Constructors

This class doesn't contains public constructors. The instance should be made through a static method.


Static Methods
Method Name Description
Behavior.getInstance(String app, Integer consentFlags) :Behavior Gets the Behavior class instance for na AppKey.
It's necessary to pass the AppKey (value provided by ClearSale) as a parameter. It's necessary to pass the Flags as parameters informing if the user consents to collect sensitive information.

Methods

Method Name Description
start() :void Start the collect of device and display information.
Exceptions:
  • CaptureWasStartedException - thrown when a previous capture was not stopped.
generateSessionID() :String Genereates and returns a session identificator.
This value must be stored and sent to ClearSale at the time of order integration (it is the parameter used in the call to the collectDeviceInformation method).
collectDeviceInformation(String sessionID) :void Perform device information collect by binding the session value.
It's necessary to pass the SessionID as a parameter (this value must be unique per session).
(*) Case it doesn't have a value, use the method generateSessionID().
(**) The SessionID minimum size is 6 characters and the maximum size is 128 characters.
Exceptions:
  • SessionIDAlreadyUsedException - thrown when the same session value is used more than once.
stop() :void Terminates the data capture process.
alllowAppList() :void Allows the collection of information about the installed applications on the device.
allowGeoLocation() :void Allows the geolocation collection.

Examples

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

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

In all examples, we assume the existence of the following variables:


To initialize the call when the screen is a Fragment.

@Override
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 é um valor de identificação único que deve ser fornecido pela ClearSale.
    mBehavior = Behavior.getInstance(context, CLEAR_SALE_APP);
    return rootView;
}

When the screen is an Activity
@Override
public void onCreate() {
    //CLEAR_SALE_APP é um valor de identificação único que deve ser fornecido pela ClearSale.
    mBehavior = Behavior.getInstance(this, CLEAR_SALE_APP);
}

To start the capture:

@Override
public void onResume() {
    super.onResume();
    try {
        mBehavior.start(); //Information capture initialization.
        String sessionId = mBehavior.generateSessionID()
        //Only on screens that is desired to sent the collected data to ClearSale
        mBehavior.collectDeviceInformation(sessionId); //Preferable after some time of user interaction.
    }
    catch (CaptureWasStartedException e) {
        //This indicates that the method mBehavior.start() was previously called but 
        //the collection wasn't properly terminated using the method mBehavior.stop().
    }catch (SessionIDAlreadyUsedException e) {
        //The same sessionID was used previously. The SessionID must be unique per collect.
    }
}

The start() and stop() methods should only be implemented on the screen where information capture will be performed. The collectDeviceInformation(SESSION_ID) method should be called when you want to send the collected information to ClearSale, on the same screen where the previous methods were implemented.

Note: The collectDeviceInformation method must be called after the start() method has already been executed.

We recommend that these methods be implemented on a 'completion' screen where there is user interaction for at least 3 seconds.

To close the capture:
@Override
public void onStop() {
    super.onStop();
    mBehavior.stop(); //Information capture termination.
}                         

Complete implementation example:

public class ImplementationExampleActivity extends AppCompatActivity {

    private Behavior mBehavior;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //CLEAR_SALE_APP é um valor de identificação único que deve ser fornecido pela ClearSale.
        mBehavior = Behavior.getInstance(this, "CLEAR_SALE_APP");
    }

    @Override
    public void onResume() {
        super.onResume();
        try {
            mBehavior.start(); //Information capture initialization
            String sessionId = mBehavior.generateSessionID();

            //Only on screens that is desired to sent the collected data to ClearSale
            mBehavior.collectDeviceInformation(sessionId); //Preferable after some time of user interaction.
        }catch (CaptureWasStartedException e) {
            //This indicates that the method mBehavior.start() was previously called but 
            //the collection wasn't properly terminated using the method mBehavior.stop().
        }catch (SessionIDAlreadyUsedException e) {
            //The same sessionID was used previously. The SessionID must be unique per collect.
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        mBehavior.stop(); //Information capture termination.
    }
}

Example project

It's possible to visualize the SDK implementation in a example project clicking here.

FAQ

Click here to access our FAQ

Privacy Details

Data usage

All information collected by ClearSale's SDK are exclusively for the purpose of fraud prevention and user protection, adherent to the security and privacy policies of Google and Apple platfoms and the LGPD. Therefore, this information must be in the application privacy policy.

Data Type Collected

ClearSale's SDK collects the following device information:

  • Precise location (when allowed by user);
  • Device advertising identification (when allowed by user);
  • Device physical/hardware characteristics (such as display, battery, keyboard, disk space, model, device name);
  • Device software characteristics (such as version, language, build, parental control);
  • Network information (such as connections, IP);
  • SimCard carrier.

Google Privacy Policy
Apple Privacy Policy

Privacy Details

Data usage

All information collected by ClearSale's SDK are exclusively for the purpose of fraud prevention and user protection, adherent to the security and privacy policies of Google and Apple platfoms and the LGPD. Therefore, this information must be in the application privacy policy.

Data Type Collected

ClearSale's SDK collects the following device information:

  • Precise location (when allowed by user);
  • Device advertising identification (when allowed by user);
  • Device physical/hardware characteristics (such as display, battery, keyboard, disk space, model, device name);
  • Device software characteristics (such as version, language, build, parental control);
  • Network information (such as connections, IP);
  • System configuration information

Learn more in: Play Store Data Safety

Google Privacy Policy

Use License

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

Copyright © 2024 ClearSale

All rights are reserved, permission is granted to use the software as is, and no modification or copying for any purpose is permitted. The Software is licensed in its current configuration “as is” and without warranty of any kind, either express or implied, including, but not limited to, warranties of merchantability, fitness for a particular purpose and non-infringement of patented rights. Under no circumstances may the Copyright holders be held liable for damages, losses, causes of action, whether in contract or tort, or other tortuous action arising from the use of the Software or other actions related to this Software without the prior written authorization of the Copyright holder.