Banner ads

This section provides details and examples of how to configure, load, and display a banner ad. You can display the ad when it loads, or on some other specific event; for example, when the user clicks a button.

Set up and load a banner ad

Before you can display an ad on your app or site, you first need to set the required configuration items, and then pass the ad placement ID to the load method.

  1. In your layout, use this code:
     <tv.superawesome.sdk.publisher.SABannerAd
         android:id="@+id/mybanner"
         android:layout_width="match_parent"
         android:layout_height="100dp"/>
    
  2. In your activity or fragment, configure the ad as required, and then call the load method:
public class MainActivity extends Activity {

    private SABanner bannerAd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // get the banner from the layout
        bannerAd = (SABannerAd) findViewById(R.id.mybanner);

        // to display test ads
        bannerAd.enableTestMode();

        // set configuration to production
        bannerAd.setConfigurationProduction();

        // set background color as transparent
        bannerAd.setColorTransparent();

        // start loading ad data for a placement
        bannerAd.load(30471);
    }
}
class MainActivity : Activity() {

    private lateinit var bannerAd: SABannerAd

    override fun onCreate(savedInstanceState: Bundle?) {
        // get the banner from the layout
        bannerAd = findViewById<SABannerAd>(R.id.mybanner)

        // to display test ads
        bannerAd.enableTestMode()

        // set configuration to production
        bannerAd.setConfigurationProduction()

        // set background color as transparent
        bannerAd.setColorTransparent()

        // start loading ad data for a placement
        bannerAd.load(30471)
    }
}
Parameter Default value
Configuration Production
Test mode Disabled
Background Color Gray

Aditional load parameters

You can also send additional options during the load() call as well as an optional OpenRTB partner ID. Both parameters are optional.

Map<String, Object> options = new HashMap<>();
options.put("key", "value");
String openRTBPartnerId = "1234";
bannerAd.load(30471, openRTBPartnerId, options);
val options = mapOf("key", "value")
val openRTBPartnerId = "1234"
bannerAd.load(30471, openRTBPartnerId, options)

Display the banner ad

To display the ad, call bannerAd.play, using either the adLoaded callback or the hasAdAvailable method:

  • Use the adLoaded callback to display the ad as soon as it is loaded. Add the callback before you call the load method. For example:
import tv.superawesome.sdk.publisher.*;

public class MainActivity extends Activity {

    private SABannerAd bannerAd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // get the banner
        bannerAd = (SABannerAd) findViewById(R.id.mybanner);

        // add a callback
        bannerAd.setListener(new SAInterface () {
            @Override
            public void onEvent(int placementId, SAEvent event) {
                if (event == SAEvent.adLoaded) {
                    bannerAd.play(MainActivity.this);
                }
            }
        });

        // start the loading process
        bannerAd.load(30471);
    }
}
import tv.superawesome.sdk.publisher.*;

class MainActivity : Activity() {

    private lateinit var bannerAd: SABannerAd

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // get the banner
        bannerAd = findViewById<SABannerAd>(R.id.mybanner)

        // add a callback
        bannerAd.setListener { placementId, event ->
            if (event == SAEvent.adLoaded) {
                bannerAd.play(this@MainActivity)
            }
        }

        // start the loading process
        bannerAd.load(30471)
    }
}
  • Use the hasAdAvailable method to display the ad on some other event, such as when the user clicks a button in the app. For example:
import tv.superawesome.sdk.publisher.*;

public class MainActivity extends Activity implements View.OnClickListener {

    private SABanner bannerAd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // get the banner
        bannerAd = (SABannerAd) findViewById(R.id.mybanner);

        // load the banner ad
        bannerAd.load(30471);
    }

    @Override 
    protected void onClick(View view) {

        // check if ad is loaded
        if (bannerAd.hasAdAvailable()) {

            // display the ad
            bannerAd.play(MainActivity.this);
        }
    }
}
import tv.superawesome.sdk.publisher.*;

class MainActivity : Activity(), View.OnClickListener {
    
    private lateinit var bannerAd: SABannerAd

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // get the banner
        bannerAd = findViewById<SABannerAd>(R.id.mybanner)

        // start the loading process
        bannerAd.load(30471)
    }

     override fun onClick(v: View?) {
        // check if ad is loaded
        if (bannerAd.hasAdAvailable()) {
            // display the ad
            bannerAd.play(this@MainActivity)
        }
    }
}