Skip to main content

Banner

Rectangular ads that can be fixed at the top or bottom of the screen.

Introduction

Images at the top, middle, or bottom of the App (supports landscape mode). Supported ad sizes: 20:3, 3:2. Effect images as follows:

20:33:2

We recommend that you download and experience the HiSavana Demo to gain a more intuitive and in-depth understanding of the SDK's features and usage. Through the Demo, you can quickly get started and explore its application in real-world scenarios.

Building the Component

Create a TBannerView object.

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.cloud.hisavana.sdk.api.adx.TBannerView
android:id="@+id/banner_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
// Bind the view from the xml layout
TBannerView tBannerView = findViewById(R.id.banner_view);
// Set the ad unit ID, where "banner_id" is the banner ad unit ID
tBannerView.setPlacementId("banner_id");

or

// Manually create a TBannerView object and add it to the parent layout, where "banner_id" is the banner ad unit ID
TBannerView tBannerView = new TBannerView(this, "banner_id");

Load Ads

Please configure the corresponding parameters and callback listeners. Be sure to carefully review the documentation for the applicable ad placement types in relevant callbacks to avoid integration discrepancies.

// Whether to hide the personalized close button, displayed by default
tBannerView.setHideAdCloseView(true);
// Set the ad listener
tBannerView.setListener(new TAdListener());
// Load the ad
tBannerView.loadAd();

// Ad listener, monitors callbacks for ad request timeout, loading completion (fill), display, click, exception, and close actions
private static class TAdListener extends AdListener {

// Exception callback (applicable ad slots: all ad slots)
@Override
public void onError(TaErrorCode adError) {
Log.d(TAG,"Ad failed callback");
}

// Loading completion callback (applicable ad slots: Splash, Interstitial, Banner, Reward)
@Override
public void onAdLoaded() {
Log.d(TAG,"Ad loaded callback");
}

// Click callback (applicable ad slots: Splash, Interstitial, Banner, Reward)
@Override
public void onAdClicked() {
Log.d(TAG,"Ad click callback");
}

// Display callback (applicable ad slots: Splash, Interstitial, Banner, Reward)
@Override
public void onAdShow() {
Log.d(TAG,"Ad show callback");
}

// Request timeout callback (applicable ad slots: all ad slots)
@Override
public void onTimeOut() {
Log.d(TAG,"Ad request timeout callback");
}

// Close callback (applicable ad slot: Banner)
@Override
public void onAdClosed(TBannerView bannerView) {
Log.d(TAG,"Ad close callback");
}
}

Display Ads

Please display the TBannerView object.

// If the current ad is loaded successfully and within the delivery period, display it; otherwise, do not display it
if (tBannerView != null && tBannerView.isReady()) {
tBannerView.show();
}

Destroy Ads

Please recycle ads promptly, otherwise the App may experience memory leaks.

@Override
public void onAdClosed(TBannerView tBannerView) {
// After the ad is closed, if you no longer continue to use the view and ad object, it is recommended that you release the view and ad object promptly to avoid memory leaks.
if(tBannerView != null){
tBannerView.destroy();
removeView(tBannerView);
tBannerView = null;
}
}
// After exiting the ad scenario, please destroy the ad object.
@Override
protected void onDestroy() {
super.onDestroy();
if (tBannerView != null) {
tBannerView.destroy();
removeView(tBannerView);
tBannerView = null;
}
}

// Remove View
private void removeView(View v) {
if (v == null) return;
ViewParent viewGroup = v.getParent();
if (viewGroup != null && viewGroup instanceof ViewGroup) {
((ViewGroup) viewGroup).removeView(v);
}
}

Other APIs

API CallDescription
tBannerView.isReady()If the current ad is loaded successfully and within the delivery period, display it; otherwise, do not display it
tBannerView.isOfflineAd()Whether the current ad is offline
tBannerView.getFillAdType()Whether the current filled ad is offline or online; 1: offline ad, 0: online ad, -1: no fill

Reminder: TBannerView is the placeholder View for Banner ads. Banner ads default to the width of the parent layout, and the height is automatically calculated based on the different ratios configured for the operational ad slot.