Menu

Banner Ad

1.1 Integration Suggestions

1.1.1 Width and Height Settings

  • Width and height can be customized, but they need to be consistent with the aspect ratio configured in the TopOn dashboard, and adjustments should be made based on actual results. For specific implementation, please refer to Demo.

1.1.2 Auto-Refresh

  • It is disabled by default. You can configure the refresh interval in the TopOn dashboard's Ad Placement Advanced Settings to enable or disable refresh.
  • The Banner Ad View must be added to the window and visible to trigger auto-refresh.
  • If the ad platform provides an auto-refresh feature, it is recommended to disable the ad platform's auto-refresh and only use TopOn's auto-refresh to avoid conflicts that may lead to unforeseen issues.
  • After enabling auto-refresh, add ATBannerView to the layout, ensure it is in a visible state, and call load() once. Subsequent display and refresh will be automatically executed by the SDK.

1.1.3 Destroying Resources

  • When it is no longer necessary to display the Banner Ad, remove ATBannerView from the layout and call the ATBannerView#destroy() method to destroy the current ad resources.

2. API Instructions

2.1 Ad Loading and Display

ATBannerView: Banner ad loading class, also a View for displaying Banner ads.

Method Description
void setPlacementId(String bannerTakuPlacementID) Set the Banner ad placement ID, where bannerTakuPlacementID is obtained by creating a Banner Ad Placement in the Taku dashboard (must be set).
void loadAd() Banner ad loading.

Ad Loading and Display:

Copy
ATBannerView mBannerView = new ATBannerView(BannerAdActivity.this); 
mBannerView.setPlacementId(bannerTakuPlacementID); 
mBannerView.loadAd();

2.2 Ad Scenario

ATBannerView:

Method Description
void setShowConfig(ATShowConfig showConfig) (Added in v6.3.10) Set the ad scenario (for subsequently displayed ads). showConfig: Extra parameters can be passed during display, as follows: 1. ATShowConfig#showCustomExt(String showCustomExt): Can pass custom parameters during display. The passed parameter will be returned via ATAdInfo#getShowCustomExt(). 2. ATShowConfig#scenarioId(String scenarioId): Can pass an ad scenario, same as setScenario(String scenario).

Scenario Example:

Copy
mBannerView.setScenario("your scenarioID");

Passing Custom Parameters During Display:

Taku SDK v6.3.10 and above supports developers passing custom parameters during display. Custom parameters passed during display are independent of custom parameters passed during Load. Custom parameters passed during display can be returned in the Taku SDK callback info.

ATBannerView:

Method Description
void setLocalExtra(Map) Set local parameters.

(1) The sizes of each Ad Source under a Banner Ad Placement should preferably be the same or have similar proportions.

(2) Before calling the load method to load an ad, the width and height values must be passed via setLocalExtra().

Copy
ATBannerView mBannerView = new ATBannerView(BannerAdActivity.this); 
mBannerView.setPlacementId(bannerTakuPlacementID); 
int width = getResources().getDisplayMetrics().widthPixels;// Set a width value, such as screen width. 
int height = (int) (width / (320 / 50f));// Convert height value according to the ratio. 
Map localMap = new HashMap<>(); 
localMap.put(ATAdConst.KEY.AD_WIDTH, width); 
localMap.put(ATAdConst.KEY.AD_HEIGHT, height); 
mBannerView.setLocalExtra(localMap); 
mBannerView.loadAd();

If the above code causes the Banner to sometimes be tall and sometimes short, use the following sample code to limit the height:

Copy
int width = getResources().getDisplayMetrics().widthPixels;// Set a width value, such as screen width. 
int height = (int) (width / (320 / 50f));// Must be consistent with the aspect ratio of the Banner Ad Source configured in the Taku dashboard. Assume the size is 320x50. 
mBannerView.setLayoutParams(new FrameLayout.LayoutParams(width, height)); 
...

ATBannerView:

Method Description
destroy Banner ad destruction (call when removing).

Banner removal can occur in the following situations:

  • When onBannerClose() is called back, manually use code to remove ATBannerView from the parent layout.
  • Manually use code to remove ATBannerView from the parent layout based on the developer's needs.

Note: When onBannerClose() is called back, if removal is not manually performed via code, the Banner Ad will be auto-refreshed once.

2.5 Ad Object

ATBannerView:

Method Description
checkAdStatus Get the status object ATAdStatusInfo of the current Ad Placement. See the API description of the ATAdStatusInfo object below.
checkValidAdCaches Query the ATAdInfo objects of all cached info for the current Ad Placement. ATAdInfo: Ad information object, can distinguish ad platforms, mainly contains ID info of third-party Mediation platforms. See ATAdInfo Info Description

ATAdStatusInfo: Status object of the Ad Placement.

Method Description
boolean isLoading() Determine whether the current Ad Placement is currently loading an ad.
boolean isReady() Determine whether the current Ad Placement has a displayable ad.
getATTopAdInfo Get the ad cache info ATAdInfo object with the highest priority for the current Ad Placement. ATAdInfo: Ad information object, can distinguish ad platforms, mainly contains ID info of third-party Mediation platforms. See ATAdInfo Info Description

2.6 Ad Listener

ATBannerView:

Method Description
setBannerAdListener(ATBannerListener listener) Set the Banner ad listener callback. ATBannerListener is the interface class that needs to implement ad event callbacks.
setAdDownloadListener(ATAppDownloadListener listener) Set the download status listener callback. listener: Download status event callback listener. Currently only supports the following platforms: Pangle (China).
setAdSourceStatusListener(ATAdSourceStatusListener listener) Set the Ad Source level event listener callback. ATAdSourceStatusListener is the interface class that needs to implement Ad Source level event callbacks. See ATAdSourceStatusListener Description

ATBannerListener: Event callback listener for Banner ads.

Method Description
void onBannerLoaded Ad load success callback.
void onBannerFailed(AdError error) Ad load failure callback. You can get the full error info via AdError.getFullErrorInfo(). Please refer to AdError. Note: Do not execute the ad loading method in this callback for retry, otherwise it may cause many unnecessary requests and may cause the app to lag.
void onBannerShow(ATAdInfo atAdInfo) Ad impression callback. ATAdInfo: Ad information object, can distinguish ad platforms, mainly contains ID info of third-party Mediation platforms. See ATAdInfo Info Description
void onBannerClicked(ATAdInfo atAdInfo) Ad click callback. Same parameter meaning as above.
void onBannerClose(ATAdInfo atAdInfo) Ad close callback (some ad platforms have this callback). Same parameter meaning as above.
void onBannerAutoRefreshed(ATAdInfo atAdInfo) Ad auto-refresh callback. Same parameter meaning as above.
void onBannerAutoRefreshFail(AdError error) Ad auto-refresh failure callback. Same parameter meaning as above.

Listener Example:

Copy
mBannerView.setBannerAdListener(new ATBannerListener() {
    @Override
    public void onBannerLoaded() { 
    }

    @Override
    public void onBannerFailed(AdError adError) {
        // Note: Do not execute the ad loading method in this callback for retry, otherwise it may cause many unnecessary requests and may cause the app to lag.
        // AdError, please refer to https://docs.takuad.com/#/zh-cn/android/android_doc/android_test?id=aderror
        Log.e(TAG, "onBannerFailed:" + adError.getFullErrorInfo());
    }

    @Override
    public void onBannerClicked(ATAdInfo atAdInfo) {
    }

    @Override
    public void onBannerShow(ATAdInfo atAdInfo) {
        // ATAdInfo can distinguish ad platforms and obtain the ad placement ID of the ad platform, etc.
        // Please refer to https://docs.takuad.com/#/zh-cn/android/android_doc/android_sdk_callback_access?id=callback_info

    }

    @Override
    public void onBannerClose(ATAdInfo atAdInfo) {
          if (mBannerView != null && mBannerView.getParent() != null) {
                ((ViewGroup) mBannerView.getParent()).removeView(mBannerView);
          }
    }

    @Override
    public void onBannerAutoRefreshed(ATAdInfo atAdInfo) {
    }

    @Override
    public void onBannerAutoRefreshFail(AdError adError) {
        // AdError: https://docs.takuad.com/#/zh-cn/android/android_doc/android_test?id=aderror
        Log.e(TAG, "onBannerAutoRefreshFail:" + adError.getFullErrorInfo());
    }
});

ATBannerExListener: Inherits from ATBannerListener, methods are the same as ATBannerListener, with additional callback descriptions as follows:

Method Description
void onDeeplinkCallback(boolean isRefresh, ATAdInfo atAdInfo, boolean isSuccess) Deeplink callback, for Adx, OnlineApi ads. isRefresh: Whether it is an auto-refresh. isSuccess: Whether successful.
void onDownloadConfirm(Context context, ATAdInfo atAdInfo, View clickView, ATNetworkConfirmInfo networkConfirmInfo) Callback method when an app-type ad click triggers a download. ATNetworkConfirmInfo: Callback info provided by the third-party ad platform (Currently only GDT's GDTDownloadFirmInfo is available.) ATAdInfo: Ad information object, can distinguish ad platforms, mainly contains ID info of third-party Mediation platforms. See ATAdInfo Info Description

ATAppDownloadListener: (Only supported by China-region SDK) Download status event callback listener.
Currently only supports the following platforms: Pangle (China).

Method Description
void onDownloadStart(ATAdInfo atAdInfo, long totalBytes, long currBytes, String fileName, String appName) Download start callback. ATAdInfo: Ad information object, can distinguish ad platforms, mainly contains ID info of third-party Mediation platforms. See ATAdInfo Info Description totalBytes: Total file size (unit: bytes). currBytes: Currently downloaded size (unit: bytes). fileName: File name. appName: App name corresponding to the file.
void onDownloadUpdate(ATAdInfo atAdInfo, long totalBytes, long currBytes, String fileName, String appName) Download progress update callback. Same parameter meaning as above.
void onDownloadPause(ATAdInfo atAdInfo, long totalBytes, long currBytes, String fileName, String appName) Download pause callback. Same parameter meaning as above.
void onDownloadFinish(ATAdInfo adInfo, long totalBytes, String fileName, String appName) Download complete callback. Same parameter meaning as above.
void onDownloadFail(ATAdInfo adInfo, long totalBytes, long currBytes, String fileName, String appName) Download failure callback. Same parameter meaning as above.
void onInstalled(ATAdInfo adInfo, String fileName, String appName) APK installation complete callback. Same parameter meaning as above.

3. Sample Code

Copy
ATBannerView mBannerView = new ATBannerView(BannerAdActivity.this);
mBannerView.setPlacementId(bannerTakuPlacementID);

int width = getResources().getDisplayMetrics().widthPixels;// Set a width value, such as screen width.
int height = ViewGroup.LayoutParams.WRAP_CONTENT;

// If the Banner sometimes appears tall and sometimes short, use this code:
// float ratio = 320/50f;// Must be consistent with the aspect ratio of the Banner Ad Source configured in the Taku dashboard. Assume the size is 320x50.
// int width = getResources().getDisplayMetrics().widthPixels;// Set a width value, such as screen width.
// int height = (int) (width / ratio);

mBannerView.setLayoutParams(new FrameLayout.LayoutParams(width, height));

frameLayout.addView(mBannerView);
mBannerView.setBannerAdListener(new ATBannerListener() {
    @Override
    public void onBannerLoaded() { 
    }

    @Override
    public void onBannerFailed(AdError adError) {
        // Note: Do not execute the ad loading method in this callback for retry, otherwise it may cause many unnecessary requests and may cause the app to lag.
        // AdError, please refer to https://docs.takuad.com/#/zh-cn/android/android_doc/android_test?id=aderror
        Log.e(TAG, "onBannerFailed:" + adError.getFullErrorInfo());
    }

    @Override
    public void onBannerClicked(ATAdInfo atAdInfo) {
    }

    @Override
    public void onBannerShow(ATAdInfo atAdInfo) {
        // ATAdInfo can distinguish ad platforms and obtain the ad placement ID of the ad platform, etc.
        // Please refer to https://docs.takuad.com/#/zh-cn/android/android_doc/android_sdk_callback_access?id=callback_info

    }

    @Override
    public void onBannerClose(ATAdInfo atAdInfo) {
          if (mBannerView != null && mBannerView.getParent() != null) {
                ((ViewGroup) mBannerView.getParent()).removeView(mBannerView);
          }
    }

    @Override
    public void onBannerAutoRefreshed(ATAdInfo atAdInfo) {
    }

    @Override
    public void onBannerAutoRefreshFail(AdError adError) {
        // AdError: https://docs.takuad.com/#/zh-cn/android/android_doc/android_test?id=aderror
        Log.e(TAG, "onBannerAutoRefreshFail:" + adError.getFullErrorInfo());
    }
});
// Passing the scenario ID into scenario will only result in data showing in the dashboard's scenario management.
mBannerView.setScenario("your scenarioID");
mBannerView.loadAd();

For detailed Banner Ad sample code, please refer to the BannerAdActivity class in Demo.

4. Ad Platform-Specific Configuration Instructions

The Taku SDK supports Admob's adaptive banners, including adaptive anchored banners and adaptive inline banners. The adaptive anchored banner is recommended. Developers need to use the following code to set the adaptive banner type, the screen orientation for adaptation, and the banner width (unit: px).

Copy
...

Map localExtra = new HashMap<>();

// since v5.7.0, Admob Adaptive Banner (Adaptive Anchored Banner, Adaptive Inline Banner)
localExtra.put(AdmobATConst.ADAPTIVE_TYPE, AdmobATConst.ADAPTIVE_ANCHORED);// Adaptive Anchored Banner
//localExtra.put(AdmobATConst.ADAPTIVE_TYPE, AdmobATConst.ADAPTIVE_INLINE);// Adaptive Inline Banner

localExtra.put(AdmobATConst.ADAPTIVE_ORIENTATION, AdmobATConst.ORIENTATION_CURRENT);
//localExtra.put(AdmobATConst.ADAPTIVE_ORIENTATION, AdmobATConst.ORIENTATION_PORTRAIT);
//localExtra.put(AdmobATConst.ADAPTIVE_ORIENTATION, AdmobATConst.ORIENTATION_LANDSCAPE);

localExtra.put(AdmobATConst.ADAPTIVE_WIDTH, width);

mBannerView.setLocalExtra(localExtra);

mBannerView.loadAd();

Note: When using Admob's adaptive banner, the height of the banner parent container must not be restricted. An example is as follows:

Copy
...
mBannerView.setLayoutParams(new FrameLayout.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT));

mBannerView.loadAd();

5.1 Pangle (China)

Copy
// Call this method before Initializing the Taku SDK.
TTATInitManager.getInstance().setIsOpenDirectDownload(false)
Previous
Custom Splash Ad
Next
Native
Last modified: 2026-07-07Powered by