Banner

Banner ads are added as a view inside your application. Consumers of your app can tap the banner ad to interact with it.

Multiple banners views may be added to the UI at any time, callbacks occur independently for each view.

The Tapdaq SDK as of v5.7.0 will handle the refresh interval itself. Please make sure that the refresh interval in the ad network dashboard is disabled, otherwise you may experience unexpected behaviour.

1. Create the view

To begin preparations for displaying a banner ad, you need to create a view. You can insert the ad straight into your XML layout files, OR create it dynamically in Java.

You can insert the ad straight into your XML layout files OR create it dynamically in Java.

After creating the view you'll then need to load the ad using Java code.

A. Create view in XML

Insert the TMBannerAdView into your layout, like so:

<com.tapdaq.sdk.TMBannerAdView
    android:id="@+id/adBanner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

Once this is done, navigate to your Activity or Fragment. Find the ad view that has been inserted into the xml layout, like so:

TMBannerAdView ad = (TMBannerAdView) findViewById(R.id.banner_ad);

B. Create view in Java

If you have created a view in XML to load the banner, you can skip this step.

To create an ad view, implement the following code:

TMBannerAdView ad = new TMBannerAdView(this); // Create ad view

yourLayout.addView(ad); // Insert view into layout

The view will be added to your layout.

2. Override TMAdListener

Next, you will need to override the TMAdListener class to receive callbacks on interstitial adverts. Create a new file and implement it like so:

public class BannerListener extends TMAdListener {
    @Override
    public void didLoad() {
        // First banner loaded into view
    }
    
    @Override
    public void didFailToLoad(TMAdError error) {
        // No banners available. View will stop refreshing
    }
    
    @Override
    public void didRefresh() {
        // Subequent banner loaded, this view will refresh every 30 seconds
    }
    
    @Override
    public void didClick() {
        // User clicked on banner
    }
}

3. Load the banner

The banner needs to be loaded for a specific size. You can see a full list of TMBannerAdSizes here.

Call the load method and set the size parameter to what you require, like so:

ad.load(this, TMBannerAdSizes.STANDARD, new TMAdListener());

Note: Not all banner sizes are available for all networks, if an ad size is unavailable for the registered Adapters, a log will be printed and no ad will be shown.

You can also override TMAdListener and implement our listener methods to have greater control over banners. For more information, see our Advanced page.

4. Destroy the banner

You must destroy the ad view which ensures it is removed from the layout and cleared from memory.

To destory the banner, implement the following within your Activity or Fragment onDestroy() lifecycle event:

@Override
protected void onDestroy() {
    TMBannerAdView ad = (TMBannerAdView) findViewById(R.id.banner_ad);
    if (ad != null) {
        ad.destroy();
    }
    super.onDestroy();
}

Build and run your application to test the advert displays correctly.

5. Banner Sizes

Banner Size AppLovin Facebook Audience Network Google Ad Mob InMobi MoPub
STANDARD 320x50 320x50 320x50 320x50 320x50
LARGE N/A 320x90 320x100 N/A N/A
MEDIUM_RECT 300x250 300x250 300x250 300x250 300x250
FULL N/A N/A 468x60 N/A N/A
LEADERBOARD N/A N/A 728x90 N/A 728x90
SMART N/A Various x 50 Various x 50 N/A N/A
SKYSCRAPER N/A N/A N/A N/A 160x600

NOTE: MoPub only support LEADERBOARDS and SKYSCRAPER types on tablet devices

Need help?

If you are having any problems integrating, feel free to contact us on [email protected] and we will be more than happy to help.

What's next?

Now that you have successfully integrated a banner into your app, what would you like to do next?