Banner
A rectangular ad that can be fixed to the top or bottom of the screen.
Introduction
The image at the top, middle or bottom of the App (supports horizontal screen). Supported ad sizes: 20:3, 3:2, the effect is as follows:
20:3 | 3:2 |
---|---|
![]() | ![]() |
Build Components
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 views in xml layout
TBannerView tBannerView = findViewById(R.id.banner_view);
// Set the ad slot ID, where "banner_id" is the banner ad slot 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 slot ID
TBannerView tBannerView = new TBannerView(this, "banner_id");
Load Ads
Please set the corresponding parameters and listening callbacks.
// Whether to hide the personalized close button, displayed by default
tBannerView.setHideAdCloseView(true);
// Set up ad listeners
tBannerView.setListener(new TAdListener());
//Load ads
tBannerView.loadAd();
// Ad listener, which monitors the callbacks of ad request timeout, loading completion (filling), display, click, exception, and closing actions
private static class TAdListener extends AdListener {
// Abnormal 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 is within the delivery period, it will be displayed; otherwise, it will not be displayed
if (tBannerView != null && tBannerView.isReady()) {
tBannerView.show();
}
Destroy Ads
Please recycle ads in time, otherwise the App will cause memory leaks.
@Override
public void onAdClosed(TBannerView tBannerView) {
// If you no longer use the view and ad objects after the ad is closed, it is recommended that you release the view and ad objects in time to avoid memory leaks.
if(tBannerView != null){
tBannerView.destroy();
removeView(tBannerView);
tBannerView = null;
}
}
// After exiting the advertising scene, please destroy the advertising 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 call | Introduce |
---|---|
tBannerView.isAdValid() | Whether the current ad is within the validity period |
tBannerView.isLoaded() | Whether the current ad is loaded successfully |
tBannerView.isReady() | If the current ad is loaded successfully and is within the delivery period, it will be displayed; otherwise, it will not be displayed. |
tBannerView.isOfflineAd() | Is the current ad offline |
tBannerView.getFillAdType() | Whether the current filled advertisement is offline or online advertising; 1: offline advertisement, 0: online advertisement, -1: no filling |
Reminder: TBannerView is the placeholder View for Banner ads. The default width of Banner ads fills the parent layout, and the height is automatically calculated according to different proportions of the operating ad space configuration.