Banner Integration Guide

Android SDK 2.0 supports banner ads in multiple sizes and includes smart resizing capabilities.

Step 1: Add BannerView to Your Layout

In your XML layout file, add the BannerView:

<com.appnext.adunits.banner.BannerView
    android:id="@+id/bannerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:bannerSize="LARGE_BANNER"
    app:placementId="YOUR_PLACEMENT_ID" />

Supported Banner Sizes:

Banner nameSize
BANNER320x50
LARGE_BANNER320x100
MEDIUM_RECTANGLE300x250

You can also choose to configure it programmatically:

  • setSize - BannerSize. Set the banner size according to the available sizes above.
  • setPlacementId - String. Set the Appnext placement ID once, per each banner.

Step 2: Load the Banner in Your Code

After adding the BannerView to your layout, you need to load an ad programmatically and set up event callbacks to track the ad’s lifecycle events.

val adCallbacks = object : AdCallbacks {
    override fun onAdClicked(packageName: String) {
        Toast.makeText(this@MainActivity, "Ad clicked", Toast.LENGTH_SHORT).show()
    }

    override fun onAdImpressionReceived(packageName: String) {
        Toast.makeText(this@MainActivity, "Impression received", Toast.LENGTH_SHORT).show()
    }

    override fun onViewLoadedSuccessfully() {}

    override fun onViewError(error: AppnextError) {
        Toast.makeText(this@MainActivity, "View error: ${error.errorMessage}", Toast.LENGTH_SHORT).show()
    }

    override fun onAdsLoadedSuccessfully() {}

    override fun onAdsLoadedError(error: AppnextError) {}
}

// Example with View Binding
binding.bannerView.load(adCallbacks)

Step 3: (Optional) Enable Smart Banner

Smart Banner dynamically resizes the banner to fit the screen width and orientation.

programmatically:

binding.bannerView.setSmartBanner(true)

Call setSmartBanner(true) before load().

Or in XML:

<com.appnext.adunits.banner.BannerView
    android:id="@+id/bannerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:placementId="YOUR_PLACEMENT_ID"
    app:bannerSize="LARGE_BANNER"
    app:isSmartBanner="true" />

Step 4: (Optional) Configure the PostBack programmatically

You can set the PostBack by defining the following:

  • `setPostBack - String. Postback parameters that will be posted to your server after the user installs an app (make sure to encode the values).

Step 5: (Optional) In-App header bidding

After creating the ad unit as described in step 2 above, it is possible to get the predicted eCPM value by executing the geteCPM function.

Upon success, the function will return ecpm object within the OnECPMLoaded callback.

interface OnECPMLoaded {
    fun ecpm(ecpm : ECPM)
    fun error(error: String)
}

The ecpm object will include the following getters:

  • getEcpm - Returns the predicted ECPM value of the banner that is about to be loaded (float type)
  • getPpr - Returns the predicted price per request value (ECPM value / 1000) (float type)
  • getCreativeId - String. Returns a unique ID of the campaign's creative.
  • getAdDomain- String. Returns the Android package name.
  • getCreativeUrl - String. Returns the URL of the campaign for User Acquisition campaign type, or the package name for Re-engagement campaign type.
  • getCampaignID - String. Returns a unique ID of the campaign
  • getCategory - String. Returns the campaign category name.


Support

If you encounter any technical issues while integrating or using the Android SDK 2.0, our team is here to help.

Contact Us

📧 Email: [email protected]

Please include:

  • App package name
  • SDK version
  • Device and OS info
  • Clear description of the issue
  • (Optional) Screenshots or logs