Implement banner ads in Android
Implement banner ads in your Android app. Create banner view objects, display them in your layout, and use a listener to manage ad events.
Read time 2 minutesLast updated a day ago
Banner ads require a specific type of dedicated banner placement. You can place the banner view object into your view hierarchy, just like you would any other view. This allows you to customize the position of each banner instance, or display multiple banners.
Script implementation
The following script sample is an example implementation for displaying two banner ads on the screen, and buttons for testing them. This example uses a single listener for multiple banner view objects. You can also have a different listener for each banner view object.Implementing the MREC banner format
To display a medium rectangle (MREC) sized ad format in your app, ensure the proper dimensions are used, such as 300x250, 300x300, or 450x450. In the case of a 300x250 MREC banner ad specifically, replace this in the following example code:With this adjusted dimension:new UnityBannerSize(320, 50)
new UnityBannerSize(300, 250)
Banner ad example
Construct aBannerShowListenerBannerConfiguration.BuilderBannerSizeBannerAd.load()LoadListenerViewad.getView()BannerShowListener showListener = new BannerShowListener(){ @Override public void onImpression(@NonNull BannerAd ad) { /* impression */ } @Override public void onClicked(@NonNull BannerAd ad) { /* clicked */ } @Override public void onFailedToShow(@NonNull BannerAd ad, @NonNull UnityAdsError error) { /* show failure */ }};BannerConfiguration.Builder builder = new BannerConfiguration.Builder( placementId, new BannerSize( 320, 50 ), showListener ) .withMediationInfo( createMediationInfo() );if ( AppLovinSdkUtils.isValidString( bidResponse ) ){ builder.withAdMarkup( bidResponse );}BannerAd.load( builder.build(), new LoadListener<BannerAd>(){ @Override public void onAdLoaded(@Nullable BannerAd ad, @Nullable UnityAdsError error) { if ( error == null ) { loadedBannerAd = ad; listener.onAdViewAdLoaded( ad.getView() ); // retrieve view via getView() } else { // failure } }} );