Skip to main content

Banner

A rectangular ad that can be anchored to the top or bottom of the screen.

Overview​

An image displayed at the top, middle, or bottom of the app. Refer to the Hisavana SSP ad source for supported sizes: 20:3 and 3:2. Sample previews:

20:33:2

We recommend downloading and trying the Mediation Demo to get a more intuitive and in-depth understanding of the SDK's features and usage.

Build the Component​

Create a TBannerView object.

// Add TBannerView in the parent layout XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e8e8e8"
android:orientation="vertical">
<com.hisavana.mediation.ad.TBannerView
android:id="@+id/banner_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:visibility="gone"/>
</RelativeLayout>
// Bind the view from the XML layout
TBannerView tBannerView = findViewById(R.id.banner_view);

Or

// Create TBannerView programmatically and add it to the parent layout
TBannerView tBannerView = new TBannerView(this);

Load Ad​

Set the required parameters and listener callbacks. Pay close attention to which ad unit types each callback applies to, to avoid integration errors.

// Set the Banner size (not supported by Hisavana SSP, AppLovin, AdColony, Max, or Yandex); see "Sizes and Types" below
tBannerView.setAdSize(BannerSize.SIZE_320x50);

/**
* Optional — only supported for "Liftoff (Vungle)" and "Yandex"
* Sets the width and height of the banner ad.
*
* "Liftoff (Vungle)": defaults to "Sizes and Types" values; if set, uses adaptive width/height in dp.
*
* "Yandex": width defaults to screen width in dp; if max height is not set, uses adaptive sticky height;
* otherwise uses adaptive inline height, in dp.
*/
// tBannerView.setCustomSizeForYandexAndLiftoff(adWidth, adHeight);

// Optional — set this if integrating AdMob collapsed banner; for other types see "Sizes and Types"
// tBannerView.setBannerType(IBannerType.BANNER_TYPE_TOP_FOLD);

// "banner_id" is the Banner ad unit ID
tBannerView.setAdUnitId("banner_id");

/**
* Optional
* For apps that need to track ad scene impressions, set the scene value here.
* The first parameter is a custom scene name; the second is the ad count.
*/
tBannerView.enterScene("banner_scene_name", 1);

// Build the ad request body
TAdRequestBody tAdRequest = new TAdRequestBody.AdRequestBodyBuild()
.setAdListener(new TAdAlliance())
.build();
// Set the ad request body
tBannerView.setRequestBody(tAdRequest);
// Load the ad and return the optimal ad within the configured wait time
tBannerView.loadAd();

// Ad listener — callbacks for load, show, click, error, and close events
private static class TAdAlliance extends TAdListener {

// Load callback (applicable to: all ad units)
@Override
public void onLoad() {
// Ad loaded callback
}

// Error callback (applicable to: all ad units)
@Override
public void onError(TAdErrorCode errorCode) {
// Ad failed callback
}

// Show callback (applicable to: Splash, Interstitial, Banner, Reward)
@Override
public void onShow(int source) {
// Ad show callback
}

// Click callback (applicable to: Splash, Interstitial, Banner, Reward)
@Override
public void onClicked(int source) {
// Ad click callback
}

// Close callback (applicable to: Splash, Interstitial, Banner, Reward)
@Override
public void onClosed(int source) {
// Ad close callback
}

// Show error callback (applicable to: all ad units)
@Override
public void onShowError(TAdErrorCode errorCode) {
// Ad show failed callback
}
}

Reminder: source indicates the ad network. Refer to the Ad Source Correlation Table. For example, if the filled ad is from Pangle, then source = 6.

Show Ad​

Display the TBannerView object.

// Banner ads display automatically after loading. If the view is hidden, check its visibility.
// If the view is added dynamically, ensure it has been added to the parent layout.
tBannerView.setVisibility(View.VISIBLE);

Destroy Ad​

Release ad resources promptly to prevent memory leaks.

@Override
public void onClosed(int source) {
// After the ad is closed, release the view and ad object if no longer needed.
if (tBannerView != null) {
tBannerView.destroy();
tBannerView.removeAllViews();
removeView(tBannerView);
tBannerView = null;
}
}
// Destroy the ad object when leaving the ad scene.
@Override
protected void onDestroy() {
super.onDestroy();
if (tBannerView != null) {
tBannerView.destroy();
tBannerView.removeAllViews();
removeView(tBannerView);
tBannerView = null;
}
}

// Remove the ad view from its parent
private void removeView(View v) {
if (v == null) return;
ViewParent viewGroup = v.getParent();
if (viewGroup instanceof ViewGroup) {
((ViewGroup) viewGroup).removeView(v);
}
}

Other APIs​

APIDescription
tBannerView.resume()Call in the lifecycle method
tBannerView.pause()Call in the lifecycle method

Reminder: After integrating Mintegral, when the system calls onResume or onPause, the app must actively call the two lifecycle methods above to reduce Mintegral error counts.

Sizes and Types​

TBannerView is the placeholder view for banner ads. Its width and height must be at least as large as the TAdBannerSize dimensions; otherwise the ad will render incorrectly. When using AdMob adaptive banner, use SIZE_320x50.

Banner Size (not supported by Hisavana SSP, AppLovin, AdColony, Max, or Yandex)

BannerSize constantSize (dp)
SIZE_320x50320*50
SIZE_320x90320*90
SIZE_320x100320*100
SIZE_320x250320*250

Banner Type (applies to AdMob)

IBannerType constantBanner Type
BANNER_TYPE_TOP_FOLDTop collapsed banner
BANNER_TYPE_BOTTOM_FOLDBottom collapsed banner
BANNER_TYPE_NORMALStandard banner