Menu

Banner Ad

1. Introduction to banner ads

    1. Banner ads provide advertising APIs in the form of Views. The width and height can be customized, but it needs to be consistent with the aspect ratio configured in the Taku background and adjusted according to the actual effect.
    2. Banner ads provide an automatic refresh function, which is not enabled by default. You can configure the refresh time or disable refresh in the advanced settings of the ad slot in the Taku backend. Note that the banner ad's View must be added to the window and visible before automatic refresh will be triggered. Even if the banner is hidden, the auto-refresh timing will not stop. If the time between hiding and re-showing exceeds the refresh time, the load method is called to refresh when the banner is re-shown.
    3. Turn off the automatic refresh function of the following advertising platforms: Inmobi, Mopub, Mintegral, Tencent Ads, Pangle. If you need to refresh automatically, please use the automatic refresh function of Taku background.
    4. Integration suggestions:
  1. Call the loading method in advance to request ads so that when needed Ability to display ads quickly when displayed.
  2. It is forbidden to execute the ad loading method in the onBannerFailed callback, otherwise it will cause useless requests and application lags.
  3. For banner ads from Baidu, Mintegral, and Juliu Media, you need to add ATBannerView to the display first position and ensure visible status before loading the ad to get the ad normally.
  4. ATBannerView objects can be reused and do not need to be recreated each time they are loaded or displayed.
  5. It is recommended to configure a preset strategy to improve the ad loading effect during the first cold start. For specific instructions and access tutorials, please refer to the SDK preset policy instructions.

  5. Notes:

      • When connecting to banner ads from the following advertising platforms, the context passed into ATBannerView must be constructed using Activity: Baidu , Guangdiantong, Pangolin, Mintegral, UnityAds, AdColony, Applovin, Chartboost, Kidoz, Pangle, StartApp.

  6. Access process suggestions:

    • Enable the automatic refresh function of the banner ad slot in the Taku background, add ATBannerView to the layout, and ensure that it is visible Then call the load method once. Subsequent display and refresh will be automatically performed by the SDK.
    • Create a ATBannerView object, add it to the location where it needs to be displayed, and then call the ATBannerView.loadAd method . After the advertisement is loaded successfully, it will be automatically displayed in the corresponding position.
    • Use the setVisibility method of ATBannerView to control display and hiding as needed.
    • When the banner ad is no longer needed, remove ATBannerView from the layout and call ATBannerView.destroy

2.API Description

2.1 Ad loading display

ATBannerView: The loading class of Banner ads is also a View that displays Banner ads

MethodParametersDescription
setPlacementId(String bannerTakuPlacementID)Set Banner's advertising slot id, where bannerTakuPlacementID is created through the Taku background< span style="color: rgb(44, 62, 80);">banner ad slot obtained. (Must be set)
loadAd-Banner ad loading


Ad loading display:

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

2.2 Advertising Scene

ATBannerView:

MethodParametersDescription
setScenario(String scenario)(Deprecated since v6.3.10) Set advertising scenes (for subsequent ads), please refer to Advertising scenes
setShowConfig(ATShowConfig showConfig)(v6.3.10+) Set advertising scenes (for subsequent ads)

showConfig: You can pass in additional parameters during display, as follows
1.ATShowConfig#showCustomExt(String showCustomExt): You can pass in custom parameters during display, and the parameters passed in will be returned through ATAdInfo#getShowCustomExt()

2.ATShowConfig#scenarioId(String scenarioId): Advertising scenarios can be passed in, the same as getNativeAd(String scenario)




Scene example:

mBannerView.setScenario("your scenarioID");

2.3 Banner ad size setting

ATBannerView:

MethodParametersDescription
setLocalExtra(MapSet local parameters


1. It is best to choose the same or close proportion of the sizes of each advertising source under the Banner ad slot

2. Call the load method to load Before advertising, you need to pass in the width and height through setLocalExtra()

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 values proportionally
Map localMap = new HashMap<>(); 
localMap.put(ATAdConst.KEY.AD_WIDTH, width); 
localMap.put(ATAdConst.KEY.AD_HEIGHT, height); 
mBannerView.setLocalExtra(localMap); 
mBannerView.loadAd();

If you use the above code, Banner sometimes appears If the height is high or sometimes low, please use the following sample code to limit the height:

int width = getResources().getDisplayMetrics().widthPixels;//Set a width value, such as screen width
int height = (int) (width / (320 / 50f));//Must be consistent with the banner ad source width to height ratio configured in the Taku backend, assuming a size of 320x50
mBannerView.setLayoutParams(new FrameLayout.LayoutParams(width, height)); 
...

2.4 Banner ad movement Except description

ATBannerView:

MethodParameterDescription
destroy-Banner ad destruction (move Executed when dividing)

1.Banner can be removed under the following circumstances

    • Callback onBannerClose (), manually call the code to remove the ATBannerView from the parent layout
    • According to the developer's needs, manually call the code to remove the ATBannerView from the parent layout

2.Note: When calling back OnBannerClose(), if not Manually calling the code to remove it will automatically refresh the Banner ad

2.5 ad object

ATBannerView:

Method ParametersDescription
checkAdStatus-Get the status object ATAdStatusInfo of the current advertising slot. See the API description of the ATAdStatusInfo object below
checkValidAdCaches-Query all cached information of the current advertising slot ATAdInfo object ATAdInfo: advertising information object, which can distinguish advertising platforms and mainly contains the id information of third-party aggregation platforms See ATAdInfo information description

ATAdStatusInfo: Status object of the ad slot

ParameterDescription
isLoading-Judgement Whether the current ad slot is loading ads
isReady-Determine whether there are ads that can be displayed in the current ad slot
getATTopAdInfo-

2.6 Advertising Monitoring

ATBannerView:  

Method ParametersDescription
setBannerAdListener(ATBannerListener listener)Set Banner advertisement listening callback, where ATBannerListener is the interface class that needs to implement advertisement event callback
setAdDownloadListener(ATAppDownloadListener listener)Set download status monitoring callback listener: Event callback monitoring for download status
Currently, only the following platforms are supported: CSJ
setAdSourceStatusListener(ATAdSourceStatusListener listener)Set up an ad source level event listening callback, where ATAdSourceStatusListener is the interface class that needs to implement the ad source level event callback, as shown in ATAdSourceStatusListener Description


ATBannerListener: It is a banner advertisement event callback listening


Method ParametersDescription
onBannerLoaded-Callback for successful advertisement loading
onBannerFailed(AdError error)Advertisement loading failure callback, all error information can be obtained through AdError. getFullErrorInfo(), please refer to AdError

Note: It is prohibited to retry the loading method of advertisements in this callback, otherwise it will cause many useless requests and may cause the application to lag
onBannerShow(ATAdInfo atAdInfo)Advertising display callback

ATAdInfo: The information object of an advertisement, which can distinguish between advertising platforms and mainly includes the ID information of third-party aggregation platforms See ATAdInfo information description
onBannerClicked(ATAdInfo atAdInfo)Ad click callback

The parameter meaning is the same as above
onBannerClose(ATAdInfo atAdInfo)Ad closure callback (some advertising platforms have this callback)

The parameter meaning is the same as above
onBannerAutoRefreshed(ATAdInfo atAdInfo)Automatic refresh callback for advertisements

The parameter meaning is the same as above
onBannerAutoRefreshFail(AdError error)Automatic refresh failure callback for advertisements

The parameter meaning is the same as above


Listening Example:


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

    @Override
    public void onBannerFailed(AdError adError) {
        //Note: It is prohibited to retry the loading method of advertisements in this callback, otherwise it will cause many useless requests and may cause the application to lag

       //AdError, please refer to https://docs.toponad.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 between advertising platforms and obtain advertising space IDs for advertising platforms
        //please refer tohttps://docs.toponad.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.toponad.com/#/zh-cn/android/android_doc/android_test?id=aderror
        Log.e(TAG, "onBannerAutoRefreshFail:" + adError.getFullErrorInfo());
    }
});


ATBannerExListener: Inherited from ATBannerListener, with the same method as ATBannerListener. Additional callback instructions are as follows:


Method ParametersDescription
onDeeplinkCallback(boolean isRefresh, ATAdInfo atAdInfo, boolean isSuccess)Deeplink callback for Adx and OnlineApi advertisements



IsRefresh: Is it an automatic refresh



IsSuccess: Is it successful
onDownloadConfirm(Context context, ATAdInfo atAdInfo, View clickView, ATNetworkConfirmInfo networkConfirmInfo)Callback method when clicking download for application advertisements.

ATNetworkConfirmInfo: Callback information provided by third-party advertising platforms (currently only available in GDTDownloadFirmInfo from Youlianghui)

ATAdInfo: The information object of an advertisement, which can distinguish between advertising platforms and mainly includes the ID information of third-party aggregation platforms See ATAdInfo information description


ATAppDownloadListener: (Only supported by SDK in China) Event callback listening for download status


Currently, only the following platforms are supported: csj

Method ParametersDescription
onDownloadStart(ATAdInfo atAdInfo, long totalBytes, long currBytes, String fileName, String appName)Start downloading callback

ATAdInfo: The information object of an advertisement, which can distinguish between advertising platforms and mainly includes the ID information of third-party aggregation platforms. Please refer to the ATAdInfo information description

TotalBytes: Total file size (in bytes)

CurrBytes: The current downloaded size (in bytes)

FileName: File name

AppName: The application name corresponding to the file
onDownloadUpdate(ATAdInfo atAdInfo, long totalBytes, long currBytes, String fileName, String appName)Download progress update callback

The parameter meaning is the same as above
onDownloadPause(ATAdInfo atAdInfo, long totalBytes, long currBytes, String fileName, String appName)Pause download callback

The parameter meaning is the same as above
onDownloadFinish(ATAdInfo adInfo, long totalBytes, String fileName, String appName)Download completion callback

The parameter meaning is the same as above
onDownloadFail(ATAdInfo adInfo, long totalBytes, long currBytes, String fileName, String appName)Download failure callback

The parameter meaning is the same as above
onInstalled(ATAdInfo adInfo, String fileName, String appName)APK installation completion callback

The parameter meaning is the same as above

3. sample code

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 there is a situation where the Banner is sometimes high and sometimes low, please use this code

//Float ratio=320/50f// Must be consistent with the banner ad source width to height ratio configured in the Taku backend, assuming a size of 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: It is prohibited to retry the loading method of advertisements in this callback, otherwise it will cause many useless requests and may cause the application to lag

    //AdError, please refer to https://docs.toponad.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 between advertising platforms and obtain advertising space IDs for advertising platforms
        //please refer to https://docs.toponad.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.toponad.com/#/zh-cn/android/android_doc/android_test?id=aderror
        Log.e(TAG, "onBannerAutoRefreshFail:" + adError.getFullErrorInfo());
    }
});
//Scenario ID is passed into the background scene management to display data
mBannerView.setScenario("your scenarioID");
mBannerView.loadAd();

For detailed banner advertising example code, please refer to:BannerAdActivity class for Demo

4. Special configuration instructions for advertising platforms

4.1 Admob adaptive banner

The Taku SDK supports Admob's adaptive banners, including adaptive anchored banners and adaptive large-sized banners. It is recommended to use adaptive anchored banners. Developers need to use the following code to set the type of adaptive banner, which screen orientation to adapt to, and the width of the banner (in px)

...

Map localExtra = new HashMap<>();

//Since v5.7.0, Admob Adaptive Banner (adaptive anchored banner, adaptive large-sized banner)
localExtra.put(AdmobATConst.ADAPTIVE_TYPE, AdmobATConst.ADAPTIVE_ANCHORED);//Adaptive anchoring banner
//localExtra.put(AdmobATConst.ADAPTIVE_TYPE, AdmobATConst.ADAPTIVE_INLINE);//Adaptive large-sized 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's parent container cannot be restricted, as shown in the following example:


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

mBannerView.loadAd();

5. Pop ups for downloading compliant applications on advertising platforms

5.1 CSJ

//Call this method before initializing the Taku SDK
TTATInitManager.getInstance().setIsOpenDirectDownload(false)


Previous
Splash ad
Next
Native
Last modified: 2025-08-21Powered by