Banners Android

Creating a Banner

To create a banner, use the Banner constructor and provide an Activity context, Chartboost location, size, and BannerCallback. A banner ad contains a BannerSize which corresponds to the following:

NameFieldSize
StandardBannerSize.STANDARD320 x 50
MediumBannerSize.MEDIUM300 x 250
LeaderboardBannerSize.LEADERBOARD728 x 90

Example:

val chartboostBanner: Banner =
   Banner(
       location = "location",
       callback = BannerCallbackImpl(),
       size = BannerSize.STANDARD,
       context = context,
   )

Chartboost’s banner extends Android View and thus can be added programmatically to your Android view layout.

After you’ve confirmed the ad has been loaded (preferably using the BannerCallback you had to provide in the banner constructor, see below for more details), you can call show() on the banner instance to actually show the banner ad.

📘

Note

  • We do not serve banner ads to apps that are opted-out of behavioral targeting.
  • You do not need to create a Banner Publishing Campaign on the Chartboost Dashboard. The banner ads are delivered through our Exchange. You only need to call on them via the SDK.
  • Your banner analytics are available in the App Analytics section of your Chartboost Dashboard.
  • Multiple banners can be displayed at once if desired.
  • Banner ads are limited to Android SDKs version 8.0.1 and above.
  • Banner ads are not supported for Amazon integrations.
  • ChartboostBanner is a View subclass able to show banner ads. Unlike other ad types, the developer is responsible for integrating the banner with the app UI and presenting it to the user.

Showing Banner Ads

Every banner has a callback which must be provided when instantiating a new Banner. It gets notified by events related to the banner life-cycle by implementing the BannerCallback interface methods. The main method you should take into consideration is onAdLoaded(), which will inform the callback asynchronously when the ad is ready to be displayed. A typical implementation would be as follows

override fun onAdLoaded(event: CacheEvent, error: CacheError?) {
   error?.run { /* Handle error */ }  ?: chartboostBanner.show()
}

For a more detailed demo, please refer to our Java sample application.


Ad Identifier

All the non-error event objects passed as parameters in delegate method calls include an adID property.

This is a string that uniquely identifies a cached ad. It might help when working with Chartboost to identify faulty creatives.‍


Public Banner Errors

All errors can be checked in the public code with the following calls:

ChartboostCacheError cacheError = new ChartboostCacheError(ChartboostCacheError.Code.INTERNAL);
cacheError.code.getErrorCode()

ChartboostShowError showError = new ChartboostCacheError(ChartboostShowError.Code.INTERNAL);
showError.code.getErrorCode()

ChartboostClickError clickError = new ChartboostClickError(ChartboostClickError.Code.INTERNAL);
clickError.code.getErrorCode()