Banner Ad

1. Basic Requirements

  • Add ADX Android SDK to your project.

  • Use the Ad Unit ID issued for Banner Ad.

  • Before requesting an ad, SDK initialization must be done first.

    • SDK initialization should be called only once when the app launches and ad requests should be made after SDK initialization is complete.

2. Setting Up the Layout

To display the BannerAd in your layout, add the ad to the corresponding Activity or Fragment.

  • Enter the Ad Unit ID and specify the banner ad size.

  • The supported sizes are listed below and must be specified.

    AD_SIZE_320x50, AD_SIZE_728x90, AD_SIZE_320x100, AD_SIZE_300x250
<com.adxcorp.ads.BannerAd
    android:id="@+id/banner"
    android:layout_width="320dp"
    android:layout_height="50dp"
    app:ADX_UNIT_ID="<BANNER_AD_UNIT_ID>"
    app:BANNER_AD_SIZE="AD_SIZE_320x50">
</com.adxcorp.ads.BannerAd>

3. Creating an Ad Object

If you prefer to write code directly instead of using layout setup, add the BannerAd to the corresponding Activity or Fragment to display it.

  • Enter the Ad Unit ID and specify the banner ad size.

  • The supported sizes are listed below and must be specified.

    AD_SIZE_320x50, AD_SIZE_728x90, AD_SIZE_320x100, AD_SIZE_300x250
public class BannerActivity extends AppCompatActivity {

    private com.adxcorp.ads.BannerAd bannerAd;
    private RelativeLayout container;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_banner);

        bannerAd = new BannerAd(this, "<BANNER_AD_UNIT_ID>", AdConstants.BANNER_AD_SIZE.AD_SIZE_300x250);
        container = (RelativeLayout) findViewById(R.id.container);

        container.addView(bannerAd);
    }
}

4. Implementation

  1. Instantiate the BannerAd and add the BannerAdListener.

  2. Call loadAd() to load the ad.

  3. When the ad is no longer needed, call BannerAd’s destroy() in the Activity or Fragment’s onDestroy() method to remove it.

public class BannerActivity extends AppCompatActivity {

    private com.adxcorp.ads.BannerAd bannerAd;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_banner);

        bannerAd = findViewById(R.id.banner);
        bannerAd.setBannerListener(new BannerAd.BannerListener() {
            @Override
            public void onAdLoaded() {
            }

            @Override
            public void onAdError(int errorCode) {
            }

            @Override
            public void onAdClicked() {
            }
        });

        bannerAd.loadAd();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (bannerAd != null) {
            bannerAd.destroy();
            bannerAd = null;
        }
    }
}

5. Callback

You can set the BannerAd’s BannerListener to receive specific events. Implement it as needed.

bannerAd.setBannerListener(new BannerAd.BannerListener() {
    @Override
    public void onAdLoaded() {
    }

    @Override
    public void onAdError(int errorCode) {
    }

    @Override
    public void onAdClicked() {
    }
});

6. Ad Revenue (OnPaidEvent)

  • You can receive the estimated ad revenue while an ad impression occurs.

  • Manually set values during mediation setup and actual values may be mixed, so it is recommended to treat this as an estimate.

  • The currency unit of eCPM is USD.

  • As shown in the example below, use OnPaidEvent to check the estimated eCPM value.

  • You can link ad revenue data with your MMP. For details, please refer to the SDK integration guides below:

 bannerAd.setOnPaidEventListener(new OnPaidEventListener() {
    @Override
    public void onPaidEvent(double ecpm) {
        // Firebase Analytics Example
        double revenue = ecpm / 1000;

        mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
        Bundle params = new Bundle();
        params.putString(FirebaseAnalytics.Param.AD_PLATFORM, "AD(X)");
        params.putString(FirebaseAnalytics.Param.AD_FORMAT, "BannerAd");
        params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, "ADX Banner Ad");
        params.putDouble(FirebaseAnalytics.Param.VALUE, revenue);
        params.putString(FirebaseAnalytics.Param.CURRENCY, "USD");
        mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, params);
        
        /// AppsFlyer Example
        double revenue = ecpm / 1000;

        Map<String, String> customParams = new HashMap<>();
        customParams.put(Scheme.AD_TYPE, "BannerAd");
        customParams.put("ad_unit_name", "ADX Banner Ad");

        AppsFlyerAdRevenue.logAdRevenue(
              "AD(X)",
              MediationNetwork.customMediation,
              Currency.getInstance(Locale.US),
              revenue,
              customParams
        );
    }
});

Last updated

Was this helpful?