Overview

Overview

Appstock SDK is a native library that monetizes Android applications.

The latest SDK version is 1.0.6.

The minimum supported Android version: Android 5.0 (API level 21)

Demo applications (Kotlin, JAVA).

Integration and configuration

Follow the integration instructions to add the SDK to your app. Once the SDK is integrated, you can provide configuration options that will help increase your revenue. Keep in mind that the SDK supports basic consent providers according to industry standards.

Appstock SDK supports the following ad formats:

The SDK can be integrated directly into your app or via supported Mediation Adapters:

Integration

Integration using dependency

In order to integrate Appstock SDK into your application, you should add the following dependency to the app/build.gradle file and sync Gradle:

dependencies {
    implementation("com.appstock:appstock-sdk:1.0.6")
}

Add this custom maven repository URL into the project/settings.gradle file:

dependencyResolutionManagement {
    repositories {
        maven {
            setUrl("https://public-sdk.al-ad.com/android/")
        }
    }
}

Manual integration using AAR files

Copy AAR files to your Android module libs folder (f.e. app/libs/).

Add dependencies to build.gradle file.

implementation(files("libs/core-release.aar"))
implementation(files("libs/omsdk.aar"))

// Only for AdMob integration
implementation(files("libs/admob-adapters-release.aar"))

// Only for AppLovin integration
implementation(files("libs/applovin-adapters-release.aar"))

Integration using ARR files requires additional dependencies. You should add ExoPlayer dependency for video ads and Google ads identifier dependency for better targeting.


implementation 'com.google.android.exoplayer:exoplayer-core:2.15.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.15.1'

implementation 'com.google.android.gms:play-services-base:18.1.0'
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'

implementation "androidx.localbroadcastmanager:localbroadcastmanager:1.0.0"

Initialization

Import the Appstock SDK core class in the main application class:

Kotlin:

import com.appstock.sdk.api.Appstock

Java:

import com.appstock.sdk.api.Appstock;

Initialize Appstock SDK in the .onCreate() method by calling Appstock.initializeSdk().

Kotlin:

class DemoApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        // Initialize Appstock SDK
        Appstock.initializeSdk(this, PARTNER_KEY)
    }
}

Java:

public class DemoApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        // Initialize Appstock SDK
        Appstock.initializeSdk(this, PARTNER_KEY);
    }
}

The Appstock.initializeSdk() method has two parameters:

  • context - the reference to the Application subclass instance

  • partnerKey - determine the Appstock server URL. The Appstock account manager should provide you with this key.

It is recommended that contextual information be provided after initialization to enrich the ad requests. For this purpose, use SDK parametrization properties.

Once SDK is initialized and all needed parameters are provided, it is ready to request the ads.

If you want to see all requests made by the SDK and verbose logs, you should enable debug mode before the initialization.

Kotlin:

Appstock.setDebugRequests(true)
Appstock.setLogLevel(Appstock.LogLevel.DEBUG)
Appstock.initializeSdk(this, PARTNER_KEY)

Java:

Appstock.setDebugRequests(true);
Appstock.setLogLevel(Appstock.LogLevel.DEBUG);
Appstock.initializeSdk(this, PARTNER_KEY);

Banner

To load and show banner ads, you should initialize, configure, and add the AppstockAdView object to the app’s layout and call the loadAd() method.

Kotlin:

private var adView: AppstockAdView? = null

private fun createAd() {
    // 1. Create AppstockAdView
    val adView = AppstockAdView(this).also { this.adView = it }

    // 2. Configure ad unit
    adView.setPlacementId(PLACEMENT_ID)
    adView.setAdSizes(AppstockAdSize(WIDTH, HEIGHT))
    adView.setAdViewListener(createListener())
    adView.autoRefreshDelay = 30

    // 3. Load ad
    adView.loadAd()

    // 4. Add AppstockAdView to the app UI
    containerForAd.addView(adView)
}

Java:

private AppstockAdView adView;

private void createAd() {
    // 1. Create AppstockAdView
    adView = new AppstockAdView(this);

    // 2. Configure ad unit
    adView.setPlacementId(PLACEMENT_ID);
    adView.setAdSizes(new AppstockAdSize(WIDTH, HEIGHT));
    adView.setAutoRefreshDelay(30);
    adView.setAdViewListener(createListener());

    // 3. Load ad
    adView.loadAd();

    // 4. Add AppstockAdView to the app UI
    getContainerForAd().addView(adView);
}

The AppstockAdView should be provided with one of the required configuration properties:

  • setPlacementId() - Unique placement identifier generated on the Appstock platform’s UI.
  • setEndpointId() - Unique endpoint identifier generated on the Appstock platform’s UI.

Which one to use depends on your type of Appstock account.

Important note: setAdSizes() should provide standard advertisement sizes, not the sizes of the screen.

It’s important to destroy ad view after leaving the screen. It cleans the resources and stops auto refresh. Or you can just stop auto refresh using stopAutoRefresh().

Kotlin:

override fun onDestroy() {
    adView?.destroy()
}

Java:

@Override
public void onDestroy() {
    super.onDestroy();
    if (adView != null) {
        adView.destroy();
    }
}

If you need to integrate video ads, you can also use the AppstockAdView object in the same way as for banner ads. The single required change is you should explicitly set the ad format via the respective property:

Kotlin:

adView.setAdUnitFormat(AppstockAdUnitFormat.VIDEO)

Java:

adView.setAdUnitFormat(AppstockAdUnitFormat.VIDEO);

Once it is done, the Appstock SDK will make ad requests for video placement and render the respective creatives.

Additionally, you can set more parameters for better advertisement targeting.

Kotlin:

adView.setAdPosition(AppstockBannerAdPosition.HEADER)
adView.setVideoPlacementType(AppstockVideoPlacementType.IN_BANNER) // Only for video ad unit format

Java:

adView.setAdPosition(AppstockBannerAdPosition.HEADER);
adView.setVideoPlacementType(AppstockVideoPlacementType.IN_BANNER); // Only for video ad unit format

You can optionally subscribe to the ad’s lifecycle events by implementing the AppstockAdViewListener interface:

Kotlin:

private fun createListener(): AppstockAdViewListener {
    return object : AppstockAdViewListener {
        override fun onAdLoaded(adView: AppstockAdView) {
            // Called when ad loaded
            Log.d(TAG, "Ad loaded successfully")
        }

        override fun onAdFailed(adView: AppstockAdView, e: AppstockAdException) {
            // Called when ad failed to load or parse
            Log.e(TAG, "Ad failed to load: " + e.message)
        }

        override fun onAdDisplayed(adView: AppstockAdView) {
            // Called when ad displayed
        }

        override fun onAdClicked(adView: AppstockAdView) {
            // Called when ad clicked
        }

        override fun onAdClosed(adView: AppstockAdView) {
            // Called when ad closed
        }
    }
}

Java:

private static AppstockAdViewListener createListener() {
    return new AppstockAdViewListener() {
        @Override
        public void onAdLoaded(AppstockAdView AppstockAdView) {
            // Called when ad loaded
            Log.d(TAG, "Ad loaded successfully");
        }

        @Override
        public void onAdFailed(AppstockAdView AppstockAdView, AppstockAdException e) {
            // Called when ad failed to load
            Log.e(TAG, "Ad failed to load: " + e.getMessage());
        }

        @Override
        public void onAdDisplayed(AppstockAdView AppstockAdView) {
            // Called when ad displayed on screen
        }

        @Override
        public void onAdClicked(AppstockAdView AppstockAdView) {
            // Called when ad clicked
        }

        @Override
        public void onAdClosed(AppstockAdView AppstockAdView) {
            // Called when ad hidden
        }
    };
}

Or you can subscribe to the video ad events (only for video ad unit format).

Kotlin:

private fun createListener(): AppstockAdViewVideoListener {
    return object : AppstockAdViewVideoListener {
        override fun onVideoCompleted(bannerView: AppstockAdView?) {
            Log.d(TAG, "Video completed")
        }

        override fun onVideoPaused(bannerView: AppstockAdView?) {
            Log.d(TAG, "Video paused")
        }

        override fun onVideoResumed(bannerView: AppstockAdView?) {
            Log.d(TAG, "Video resumed")
        }

        override fun onVideoUnMuted(bannerView: AppstockAdV