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).
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:
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.
'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" implementation
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
.initializeSdk(this, PARTNER_KEY)
Appstock}
}
Java:
public class DemoApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Initialize Appstock SDK
.initializeSdk(this, PARTNER_KEY);
Appstock}
}
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:
.setDebugRequests(true)
Appstock.setLogLevel(Appstock.LogLevel.DEBUG)
Appstock.initializeSdk(this, PARTNER_KEY) Appstock
Java:
.setDebugRequests(true);
Appstock.setLogLevel(Appstock.LogLevel.DEBUG);
Appstock.initializeSdk(this, PARTNER_KEY); Appstock
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
.setPlacementId(PLACEMENT_ID)
adView.setAdSizes(AppstockAdSize(WIDTH, HEIGHT))
adView.setAdViewListener(createListener())
adView.autoRefreshDelay = 30
adView
// 3. Load ad
.loadAd()
adView
// 4. Add AppstockAdView to the app UI
.addView(adView)
containerForAd}
Java:
private AppstockAdView adView;
private void createAd() {
// 1. Create AppstockAdView
= new AppstockAdView(this);
adView
// 2. Configure ad unit
.setPlacementId(PLACEMENT_ID);
adView.setAdSizes(new AppstockAdSize(WIDTH, HEIGHT));
adView.setAutoRefreshDelay(30);
adView.setAdViewListener(createListener());
adView
// 3. Load ad
.loadAd();
adView
// 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() {
?.destroy()
adView}
Java:
@Override
public void onDestroy() {
super.onDestroy();
if (adView != null) {
.destroy();
adView}
}
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:
.setAdUnitFormat(AppstockAdUnitFormat.VIDEO) adView
Java:
.setAdUnitFormat(AppstockAdUnitFormat.VIDEO); adView
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:
.setAdPosition(AppstockBannerAdPosition.HEADER)
adView.setVideoPlacementType(AppstockVideoPlacementType.IN_BANNER) // Only for video ad unit format adView
Java:
.setAdPosition(AppstockBannerAdPosition.HEADER);
adView.setVideoPlacementType(AppstockVideoPlacementType.IN_BANNER); // Only for video ad unit format adView
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
.d(TAG, "Ad loaded successfully")
Log}
override fun onAdFailed(adView: AppstockAdView, e: AppstockAdException) {
// Called when ad failed to load or parse
.e(TAG, "Ad failed to load: " + e.message)
Log}
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
.d(TAG, "Ad loaded successfully");
Log}
@Override
public void onAdFailed(AppstockAdView AppstockAdView, AppstockAdException e) {
// Called when ad failed to load
.e(TAG, "Ad failed to load: " + e.getMessage());
Log}
@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?) {
.d(TAG, "Video completed")
Log}
override fun onVideoPaused(bannerView: AppstockAdView?) {
.d(TAG, "Video paused")
Log}
override fun onVideoResumed(bannerView: AppstockAdView?) {
.d(TAG, "Video resumed")
Log}
override fun onVideoUnMuted(bannerView: AppstockAdV