The RTBBannerAdProvider gives the app complete control over the lifecycle of a specific banner impression. Specifically, the app can load a banner ad separately from rendering it later. The app can load an ad with a specific configuration and get notified about the outcome of that specific load request via the RTBBannerAdLoadDelegate. Hence, the usage of the RTBBannerAdProvider differs from using RTBBannerView.
Request Ad
To load a banner ad, you will need to pass an instance of RTBBannerRequestConfiguration with placementID and the bundleId. Please contact our support to get the needed IDs.
You will be notified about the loading success or failure through the RTBBannerAdLoadDelegate instance passed as bannerLoadListener. If the ad loads successfully, you will obtain RTBBannerBid instance that can later be used to obtain banner view.
Get Loaded Banner View
Once the banner is loaded and the method bannerAdDidReceiveAd() is called, you can get the loaded banner view by calling the RTBBannerAdProvider.getBannerView(context: Context, bannerBid: RTBBannerBid, listener: RTBBannerAdInteractionDelegate?): View method. You can also pass optional interactionListener that will be notified about banner events like clicks.
override fun bannerAdDidReceiveAd(bannerBid: RTBBannerBid) {
// Optionally - examine bid details:
val priceCPM = bannerBid.priceCPM
val bannerView = RTBBannerAdProvider.getBannerView(context, bannerBid, interactionListner)
// Add the banner view to the layout
}
The currency of bidFloor and priceCPM parameters is USD.
Complete Code Example
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Prepare request configurations
val configuration = RTBBannerRequestConfiguration(placementId, bundleId)
configuration.sellerId = "<SELLERID>" // Optional
configuration.bidFloor = <BID_FLOOR> // Optional
// Request a banner ad
RTBBannerAdProvider.loadBannerAd(this, RTBBannerSize.banner320x50, rtbBannerRequestConfiguration, createBannerLoadDelegate())
}
private fun createBannerLoadDelegate(): RTBBannerAdLoadDelegate {
return object : RTBBannerAdLoadDelegate {
override fun bannerAdDidReceiveAd(bannerBid: RTBBannerBid) {
// Banner has been loaded
val banner = RTBBannerAdProvider.getBannerView(this, bannerBid, createInteractionDelegate())
// Add the banner view to layout
}
override fun bannerAdDidFailToReceiveAd(errorMessage: String) {
// Failed to load a banner ad
}
}
}
private fun createInteractionDelegate(): RTBBannerAdInteractionDelegate {
return object : RTBBannerAdInteractionDelegate {
override fun bannerAdDidRecordClick() {
// The banner received a click
}
override fun bannerAdDidPauseForAd() {
// The app paused after the user clicked on the ad
}
override fun bannerAdDidResumeAfterAd() {
// The app resumed after returning from ad
}
override fun bannerAdDidFailToRender(error: String) {
// Banner failed to render properly
}
}
}
}