Suggested Banner Integration Guide
Android SDK 2.0 supports suggested banner ads and includes smart resizing capabilities.
Suggested banner size is : 320x100
Step 1. Add SugegstedBannerView to Your Layout
In your XML layout file, add the SugegstedBannerView:
<com.appnext.adunits.suggestedbanner.SugegstedBannerView
android:id="@+id/suugestedBannerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:placementId="YOUR_PLACEMENT_ID" />
You can also choose to configure it programmatically:
- setPlacementId - String. Set the Appnext placement ID once, per each banner.
Step 2. Load the Suggested Banner in Your Code
After adding the SugegstedBannerView 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.suugestedBannerView.load(context,adCallbacks)
//This is how the load function is built and optional parameters
fun load(
context: Context, //mandatory
callbacks: AdCallbacks? = null, //mandatory
postback: String? = "", //optional
placementId: String = "", //optional
searchKeyword : String = "" //optional
)
Step 3. (Optional) Enable Smart Banner
Smart Banner dynamically resizes the banner to fit the screen width and orientation.
Default value is false.
programmatically:
binding.suugestedBannerView.setSmartBanner(true)
Call setSmartBanner(true) before load().
Or in XML:
<com.appnext.adunits.suggestedbanner.SugegstedBannerView
android:id="@+id/suggestedBannerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:placementId="YOUR_PLACEMENT_ID"
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
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 an 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.
Step 6. (Optional) - Set search criteria
By default, the banner settings will be loaded with pre-defined settings. You can change these settings by setting values in the view.
Setters that are relevant to all banner sizes:
- setCategories - String. Set preferred ad categories (comma-separated)
- setSpecificCategories - Set specific ad categories (comma-separated)
- setSearchByPackage - Set specific package
- searchKeyword - searching by keyword can be achieved by adding the keyword in the load ads function.
fun load(
context: Context, //mandatory
callbacks: AdCallbacks, //mandatory
postback: String, //optional
placementId: String, //optional
searchKeyword : String //optional
)
Updated 3 days ago