Banner¶
Integration¶
Android apps are build of several view objects. An ADvantage banner is also a view (to be more exact, it is an RelativeLayout) displaying HTML5 ads that respond to user interaction (touch, wipe, click and etc.).
To add a banner to your view it takes only a few lines of code:
- Create an new instance of ADvantage instance in code (pass your license key, siteId and position to its constructor)
private var banner: Advantage? = null
...
banner = Advantage(this, "<LICENSE_KEY>", "<SITE_ID>", "<POSITION>")
banner?.sslEnabled = true
//Optionally add your custom loading animation
banner?.setLoadingAnimationImageViewResourceId(R.drawable.loading_animation)
private Advantage banner;
...
banner = new Advantage(this, "<LICENSE_KEY>", "<SITE_ID>", "<POSITION>");
banner.setSSLEnabled(true);
//Optionally add your custom loading animation
banner.setLoadingAnimationImageViewResourceId(R.drawable.loading_animation);
Note
- You have to enable SSL before calling
showAd()
. - SSL enabled is required for every new license.
- For customers where SSL has not yet been activated and you would like to switch, please contact us.
- Add the ADvantage instance to your layout/content view
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
LinearLayout container = findViewById(R.id.container);
//Add ADvantage view to your layout
container.addView(banner);
- Add the EventHandler in order to handle ADvantage events (For more information please visit ADvantage events):
//Add the EventHandlers to handle ADvantage events
banner.setEventHandler(...);
- Load and show the ad via your ADvantage instances showAd() method.
//Show banner...
banner.showAd();
- Override
onPause
andonResume
methods for better memory handling (For more information please visit ADvantage lifecycle):
// Important methods for the ADvantage lifecycle
override fun onPause() {
super.onPause()
banner?.setActivityState(Advantage.ActivityState.PAUSE)
}
override fun onResume() {
super.onResume()
banner?.setActivityState(Advantage.ActivityState.RESUME)
}
// Important methods for the ADvantage lifecycle
@Override
protected void onPause() {
super.onPause();
if(banner != null)
banner.setActivityState(ActivityState.PAUSE);
}
@Override
protected void onResume() {
super.onResume();
if(banner != null)
banner.setActivityState(ActivityState.RESUME);
}
Tip
The best place to do all this is in your Activity's onCreate()
method.
Transparency Consent Framework 2.0 (TCF 2.0)¶
We strongly recommend the use of a Consent Management Platform (CMP) compliant with TCF 2.0 if your audience on your website/app, in whole or in part, is located within the EU.
Click here for instructions on how to hand over TCF 2.0 Consent to ADvantage.