1. Home
  2. Docs
  3. Publisher
  4. Sandstorm-SDK integration
  5. Android



SandstormSDK provides in-game, intermission and bounty audio ads and allows publishers to generate new revenues from world-class brands.
Generator and player for personalized VAST audio advertisement. Sandstorm is an all-you-need SDK for your in-app audio advertisement.
The framework provides automatically generated, personalized ads with an already prepared player. Use it without additional third-party configuration to play the ad in your app.


Below is a tutorial on how to add the library to your project and how to use it. More information on specific methods can be found in the documentation.

Minimum requirements

  • minSdkVersion is set to 24
  • targetSdkVersion must be set at least to 32
  • multiDexEnabled shall be set to true


Choose SDK versions

You have to decide which version of SDK you want to use. Two available:

SandstormSDK – contains SDK functionality with additional user targeting provided by NumberEight; this version will ask users for extra permissions (i.e. location)

NumberEight is an AI software, which predicts the live context of a user (e.g. running, commuting) from sensors present in the device, and then packages them neatly into ID-less behavioural audiences (e.g. joggers, frequent shoppers).

SandstormLiteSDK – contains SDK functionality without extra user targeting; this version won’t ask users for extra permissions

The method of installation depends on how the library was given. If an aar file was provided then adding to the project is by manual means.
Regardless of how you obtained the library, you must add the following code to the application manifest between the application tags:

<activity android:name="com.siroccomobile.adtonos.thundersdk.ui.ThunderActivity"
    android:theme="@style/AppTheme.Transparent" />

Manual installation

Copy the aar files to the “libs” directory of your project.

Add Repository

In the base project gradle file, find the “repositories” section and add the following entry to it, if you want to use the full version of the library:

allprojects {
    repositories {
        ... other repositiories
        maven {
            // Required for full version with additional targeting
            url 'https://repo.numbereight.ai/artifactory/gradle-release-local'

Add dependencies

In the application gradle file, find the “dependencies” section and add the following entries to it.

// Required for lite version

// Required for full version with additional targeting
implementation('ai.numbereight.sdk:nesdk:3.4.0@aar') { transitive = true }

// The following libraries can be updated according to project needs. 
// The versions listed are recommended.

System permissions

During the first startup, the library will ask the user to grant system permissions. The process is automatic.

The following system permissions are used by the library. They will be merged during the build, so you do not need to declare them again in the application manifest.

<!-- Required for full and lite version -->
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />

<!-- Required for full version -->
<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.READ_PHONE_STATE" />
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.sensor.gyroscope" android:required="false" />
<uses-feature android:name="android.hardware.sensor.barometer" android:required="false" />
<uses-feature android:name="android.hardware.sensor.compass" android:required="false" />
<uses-feature android:name="android.hardware.sensor.light" android:required="false" />
<uses-feature android:name="android.hardware.sensor.proximity" android:required="false" />


To work properly, the SDK needs consent. Depending on the region, please ask the user if they agree to the following.
In some regions, such as the EU, consent is required to allow third parties to store data on users’ devices for example.


Below is a list of what is included in this option:

  • PROCESSING – Allow processing of data.
  • SENSOR_ACCESS – Allow use of the device’s sensor data.
  • STORAGE – Allow storing and accessing the information on the device.
  • USE_FOR_AD_PROFILES – Allow the use of technology for personalised ads.
  • USE_FOR_PERSONALISED_CONTENT – Allow use of technology for personalised content.
  • USE_FOR_REPORTING – Allow use of technology for market research and audience insights.
  • USE_FOR_IMPROVEMENT – Allow the use of technology for improving products.
  • LINKING_DEVICES – Allow linking different devices to the user through deterministic or probabilistic means.
  • USE_OF_DEVICE_INFO – Allow use of automatically provided device information such as manufacturer, model, IP addresses and MAC addresses.
  • USE_FOR_SECURITY – Allow use of independent identifiers to ensure the secure operation of systems.
  • USE_FOR_DIAGNOSTICS – Allow processing of diagnostic information using an independent identifier to ensure the correct operation of systems.
  • PRECISE_GEOLOCATION – Allow use of precise geolocation data (within 500 metres accuracy).


It is possible to start adTonos with an option without accepted consent, but it will not collect data about the user then, so the advertisement will not be personalized appropriately to the user.

Sequence of steps

  • Call the ATSandstormSDK.initialize method at the initialization time of the app.
  • Call ATSandstormSDK.addCallback with Thunder callback to listen for SDK state changes
  • Call the ATSandstormSDK.start method once the user has agreed to the privacy policy by providing the type of consent.
  • Call ATSandstormSDK.createBuilder method and fill AdTonos key with ThunderVastUrlBuilder.setAdTonosKey
  • On the instance of ThunderVastUrlBuilder call ThunderVastUrlBuilder.build method to get URL
  • Repeat the last step every time the VAST link is required
  • Call ATSandstormSDK.addCallback with Sandstorm callback to listen for vast player changes
  • To get ads call ATSandstormSDK.requestAds and pass their instance of ThunderVastUrlBuilder
  • Call ATSandstormSDK.playAd / ATSandstormSDK.pauseAd
  • If the foreground is lost, then the ATSandstormSDK.pauseAd method has to be invoked
  • When the application is being destroyed call ATThunderSDK.dispose method to free all resources

Start SDK and create a builder


The first necessary step in the project is to call the ATSandstormSDK.Initialize method. It should be called at the start of the application when the other components are created. The method is safe to be called multiple times. The Initialize method must be called every time the application starts. Below is an example of how this should be done:

ATSandstormSDK.initialize(context = applicationContext)

Number eight key

This chapter is required for the full version with additional targeting.
Before calling the start method please invoke setNumberEightKey method with your obtained key to ensure proper work of SDK.



The library requires certain permissions and user consent for data collection.
Therefore, one of the initial screens should show the user the terms and conditions containing
the necessary information about the use and processing of personal data. This is done when
the user first interacts with the application, so this is a good time to call the Start method.
The method takes the consent flag as a parameter and then asks the user for the system permissions
necessary for the application to work. The start method must be called every time the application starts.
Additionally, the LoadLatestConsents method can be used, which returns the most recently granted consents.
Below is an example of how this can be done:

Pass one of the available targeting types as a function parameter:

  • AdTonosConsent.None
  • AdTonosConsent.AllowAll
ATSandstormSDK.start(context = applicationContext, consent = AdTonosConsent.None)

To check if SandstormSDK is started it is possible to use the isStarted variable.


Save consents

In case you want to change the consent, you can use the method save.

ATSandstormSDK.saveConsents(context, AdTonosConsent.None)

Load consents

You can also get the last set of consents using the method loadLatestConsent.


To generate a VAST link, create a builder and then set the AdTonos key. Optionally, if you want to use a language other than preferred in the system, you can set it with .setLanguage(lang:String). Language must be provided in ISO-639-1 or ISO-639-2 format.

val builder = ATThunderSDK.createBuilder()
    .setAdTonosKey("XXXXX")          // Sets developer key.
    .setLanguage("en")               // Sets user language, if different than a system defined.
    .setAdType(VastAdType.bannerAd)  // Sets the type of ad. By default VastAdType.regular is set.
  • AdTonos key – Where to find AdTonosKey?
    It’s provided by AdTonos on the portal and can be extracted from the link:


where XXXXX is the AdTonos key. AdTonos usually provides two links, one for testing purposes and one for release. During development testing, a key shall be used.

Sample usage

fun onAppStarted() {
    CoroutineScope(Dispatchers.Default).launch {
        val consents = ATSandstormSDK.loadLatestConsents()


        if (consents == null) {
            //show dialog on main thread
            withContext(Dispatchers.Main) {
        } else {
            ATSandstormSDK.start(applicationContext, consents)

fun showPrivacyPolicyDialog() {
    // provide result from dialog to onPrivacyPolicyPopupClosed

fun onPrivacyPolicyPopupClosed(consents: AdTonosConsent) {
    ATSandstormSDK.start(context = applicationContext, consents = consents)

To listen for events occurring in SDK you have to create and add ThunderCallback. Callbacks are called on the UI thread, but they should not be blocked.

Usage with Thunder callback:

fun onAppStarted() {
    CoroutineScope(Dispatchers.Default).launch {
        val consents = ATSandstormSDK.loadLatestConsents()


        if (consents == null) {
            //show dialog on main thread
            withContext(Dispatchers.Main) {
        } else {
            ATSandstormSDK.start(applicationContext, consents)

fun showPrivacyPolicyDialog() {
    // provide result from dialog to onPrivacyPolicyPopupClosed

fun onPrivacyPolicyPopupClosed(consents: AdTonosConsent) {
    ATSandstormSDK.start(context = applicationContext, consents = consents)

suspend fun addCallback(context: Context) {
    ATSandstormSDK.addCallback(object : ThunderCallback {
        override fun onStarted() {
            Log.d("ADTONOS", "SDK Started")

            CoroutineScope(Dispatchers.Default).launch {

        override fun onError(error: ThunderError) {
            Log.e("ADTONOS", error.errorMessage ?: error.toString())

Playing Ads

There are several steps to follow to play the ads. First of all, using the ThunderVastUrlBuilder, enter the AdTonos key. The next step is to request ads using the RequestForAds method. The next steps are to wait for the ads to be obtained and to run the ads. A callback can be useful here to provide information about the current state and any errors. Below is an example of a class that will cause an advertisement to play.

There are 2 things to note:

  • the requestForAds, clear, dispose, playAd, pauseAd methods must be run on the UI thread. How to call it is left to developers, due to the possibility of using RxJava or coroutines and proper thread management.
  • callbacks are called on the UI thread, for this reason, they should not be blocked by unnecessary operations.
import com.siroccomobile.adtonos.sandstormsdk.api.ATSandstormSDK

class SandstormAdsPlayback: SandstormCallback
    private val uiScope = CoroutineScope(Dispatchers.Main)

    override fun onVastAdPaused() {
        Log.d("ADTONOS", "Ad Paused")

    override fun onVastAdPlayStarted() {
        Log.d("ADTONOS", "Ad Play")

    override fun onVastAdsAvailabilityExpired() {
        Log.d("ADTONOS", "Ad Expired")

    override fun onVastAdsEnded() {
        Log.d("ADTONOS", "Ad Ended")

    override fun onVastAdsLoaded() {
        Log.d("ADTONOS", "Ad Loaded")

    override fun onVastAdsStarted() {
        Log.d("ADTONOS", "Ad Started")

    override fun onVastError(error: AdTonosVastError) {
        Log.e("ADTONOS", "Ad Error")

    suspend fun requestAds(context: Context) {
        without thunder callback:

        val isStarted = GlobalScope.async {
            do {
            } while (!ATSandstormSDK.isStarted())


        val builder = ATSandstormSDK.createBuilder()
            .setAdTonosKey("") //PASS HERE YOUR ADTONOS KEY

        withContext(Dispatchers.Main) {
            when (ATSandstormSDK.requestForAds(context, builder)) {
                SandstormAdRequestResult.success -> {
                    Log.d("ADTONOS", "Request started")
                SandstormAdRequestResult.inProgress -> TODO()
                SandstormAdRequestResult.failed -> TODO()
                SandstormAdRequestResult.alreadyPrepared -> TODO()
                SandstormAdRequestResult.invalidKey -> TODO()
                SandstormAdRequestResult.invalidLanguage -> TODO() 

Call onPause when the foreground is lost

If the foreground is lost, then the pauseAd method has to be invoked.

// Invoked from main activity
override fun onPause() {

    //If foreground is lost,then the pause method has to be invoked.

Clearing and Disposing

You can call the clear method at any time, which will stop the playback and clear the current state of the ad playback. After calling the clear method, the ad request must be executed again. The clear method also executes automatically when the ad playback has finished or after critical errors that prevent playback.


To release the memory used by the library completely, call the dispose method. This is usually done when exiting the application. Note that after the dispose method is executed, the only way to restore ad functionality is to call initialize and start again.

// Invoked from main activity
override fun onDestroy() {



The SDK can play audio ads with a banner. If you want to use such an advertisement use the setAdType(VastAdType.bannerAd) method in ThunderVastURLBuilder

val builder = ATThunderSDK.createBuilder()
    .setAdTonosKey("XXXXX")          // Sets developer key.
    .setLanguage("en")               // Sets user language, if different than a system defined.
    .setAdType(VastAdType.bannerAd)  // Sets the type of ad. By default VastAdType.regular is set.

It’s necessary to set the banner container view declared in XML if you want to use banner ads. It’s also necessary to add a banner view to all activity layouts if the banner should be visible across all activities. Additionally to avoid lifecycle problems add setBannerContainer and addLifecycleObserver methods in onResume of all activities.

    android:layout_height="wrap_content" />

Setting the banner position

The SDK offers to set the banner position, to do this use the following method:


It is possible to display the banner view at the top of the screen or the bottom.

By default, the banner will be displayed at the top of the screen. The method needs to be called before the ads are played.


Please see extended documentation from the repository to get information about possible errors and other methods that can be invoked.