2.3. Advertising form
Hisavana currently supports advertising forms including Banner,Interstitial,Native,Splash which four types of advertising, access methods are different, you can refer to the next description of the access methods of various forms of advertising.
Pay attention
- Please execute all advertising operations in the main thread.
- SDK cannot be initialized by multiple processes at the same time.
- Make sure to initialize the ad SDK before making an ad request
- All ads should be loaded () once and show () once, so that you can ensure that every time you get the best ads, and don't load () once and show () many times.
- Avoid multiple loadAd() on the same object, because multiple loadAd() on the same object will overwrite the last requested ad.
2.3.1 Banner Ads
Brief introduction
Pictures at the top, middle or bottom of the app. Supported advertisement sizes: 20:3, 3:2, and the renderings are as follows:
20:3 | 3:2 |
---|---|
![]() ![]() | ![]() |
Access steps
2.3.1.1 Add TBannerView
First, add TBannerView to the page where the banner advertisement is to be displayed, which can be added to the corresponding XML file:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.cloud.hisavana.sdk.api.adx.TBannerView
android:id="@+id/bannerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_test"
android:background="@drawable/gd_border_radius_4" />
</RelativeLayout>
2.3.1.2 Initialize advertisement object
// banner is slot id
adview.setPlacementId("banner");
adview.setListener(new Listener() {
@Override
public void onError(TaErrorCode adError) {
Log.e(TAG,"onError " + adError);
}
@Override
public void onAdLoaded() {
Log.d(TAG,"onAdLoaded");
}
@Override
public void onAdClicked(DownUpPointBean pointBean) {
Log.d(TAG,"onAdClicked");
}
@Override
public void onAdShow() {
Log.d(TAG,"onAdShow");
}
@Override
public void onTimeOut() {
Log.d(TAG,"onTimeOut");
}
@Override
public void onBiddingSuccess(BidInfo bidInfo) {
//sdk2.0.1.1+New version, get price successfully
//adview.loadAd(bidInfo);
}
})
2.3.1.3 Start requesting ads
Request advertisement by loadad ().
adview.loadAd();
2.3.1.4 Display advertising
if (adview != null && adview.isAdValid()) {
adview.show();
}
2.3.1.5 Close ads
@Override
public void onAdClosed() {
//This method does not call back in native and banner advertisements, but calls back when inserting and opening advertisements are closed.
}
@Override
public void onAdClosed(TBannerView tBannerView) {
//sdk2.1.0.0+version added, which can call adview. destroy() to close advertisements after triggering shutdown
if(tAdBannerView != null){
tAdBannerView.destroy();
tAdBannerView = null;
}
}
2.3.1.6 Destroy advertisements
When the advertisement is displayed, exit the interface and destroy the advertisement.
@Override
protected void onDestroy() {
super.onDestroy();
if (adview != null) {
adview.destroy();
adview.removeAllViews();
adview = null;
}
}
2.3.1.7 Other APIs
tAdBannerView.getFillAdType();
Note: To judge whether the filled advertisement belongs to offline or online advertisement, 1: offline advertisement 0: online advertisement -1: no filling.
adview.setBidding(true)
adview.loadAd()//These two APIs are used together to initiate bidding requests
adview.loadAd(BidInfo bidInfo) //Initiate a material request after successful bidding
Note: The HeaderBidding function has been added to the SDK2.0.1.1+ version, and the above two APIs have been added.
TBannerView
- Tbannerview is the placeholder view of banner ads. the default width of banner ads is full of the parent layout, and the height is automatically calculated according to different proportions of operational advertising space configuration.
2.3.2 Interstitial Ads
Brief introduction
The format of the advertisement that appears when the user opens or switches to your application.
The supported advertising sizes are 1:1, 9:16, 3:2, and the effect pictures are as follows:
1:1 | 9:16 | 3:2 |
---|---|---|
![]() | ![]() | ![]() |
Access steps
2.3.2.1 Initialize advertisement object
TInterstitial mAdInterstitial = new TInterstitial("interstitial");
mAdInterstitial.setListener(new AdListener() {
@Override
public void onError(TaErrorCode adError) {
Log.e(TAG,"onError " + adError);
}
@Override
public void onAdLoaded() {
Log.d(TAG,"onAdLoaded");
}
@Override
public void onAdClicked(DownUpPointBean pointBean) {
Log.d(TAG,"onAdClicked");
}
@Override
public void onAdShow() {
Log.d(TAG,"onAdShow");
}
@Override
public void onTimeOut() {
Log.d(TAG,"onTimeOut");
}
@Override
public void onBiddingSuccess(BidInfo bidInfo) {
//sdk2.0.1.1+New version, get price successfully
//mAdInterstitial.loadAd(bidInfo);
}
});
2.3.2.2 Start requesting ads
mAdInterstitial.loadAd();
2.3.2.3 Display advertising
if (mAdInterstitial != null) {
mAdInterstitial.show();
}
2.3.2.4 Destroy advertisements
if (mAdInterstitial != null) {
mAdInterstitial.destroy();
mAdInterstitial = null;
}
2.3.2.5 Other APIs
mAdInterstitial.getFillAdType();
Note: To judge whether the filled advertisement belongs to offline or online advertisement, 1: offline advertisement 0: online advertisement -1: no filling.
mAdInterstitial.setBidding(true)
mAdInterstitial.loadAd()// These two APIs are used together to initiate bidding requests
mAdInterstitial.loadAd(BidInfo bidInfo) //Initiate a material request after successful bidding
Note: The HeaderBidding function has been added to the SDK2.0.1.1+ version, and the above two APIs have been added.
2.3.3 Native Ads
Brief introduction
Information flow, including large and small pictures, text and buttons. It is divided into self rendering and template rendering.
Self rendering: the actual presentation style is determined by the media. Display native ads in your app. When you use hisavana API to access ads, you will create the following native ads.
Template rendering (applicable to sdk version 2.1.0.0+): The actual presentation style is determined by the sdk. The sdk matches the template according to the template type delivered by the server and performs rendering, and the media can fine-tune the presentation style. Support the context of the upper picture, the upper text of the lower picture, the right text of the left picture, the left text of the right picture, vertical picture and full screen picture. The effect is as shown in the figure:
Above and below | Below picture above | Picture on the left and text on the right |
![]() | ![]() | ![]() |
It is recommended not to limit the layout height |
Right image, left text | Vertical image | Full screen image |
---|---|---|
![]() | ![]() | ![]() |
It is recommended not to limit the layout height | It is recommended not to limit the layout height, it is recommended to limit the layout width | It is recommended that the layout width and height be match_parent |
Access steps
2.3.3.1 Add TAdNativeView
First, add tnativeview to the layout file to display native advertisements
<com.cloud.hisavana.sdk.api.view.TNativeView
android:id="@+id/native_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
2.3.3.2 New layout file
Create a new layout file of native advertising elements native_ install. xml, in which the icon in the advertising element is rendered with ImageView, and the large image is rendered with mediaview, as follows:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ad_unit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/item_background"
android:orientation="vertical">
<com.cloud.hisavana.sdk.api.view.MediaView
android:id="@+id/coverview"
android:layout_width="match_parent"
android:layout_height="200dp"
tools:background="#22000000"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<com.cloud.hisavana.sdk.api.view.AdChoicesView
android:id="@+id/ad_choice"
android:layout_width="@dimen/dp_12"
android:layout_height="@dimen/dp_12"
app:layout_constraintLeft_toRightOf="@+id/native_ad"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/native_ad"
android:layout_width="@dimen/dp_12"
android:layout_height="@dimen/dp_12"
android:src="@drawable/hisavana_ad_big"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
</ImageView>
<ImageView
android:id="@+id/native_ad_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
tools:background="#22000000"
app:layout_constraintTop_toBottomOf="@+id/coverview"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/native_ad_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:ellipsize="end"
android:lines="1"
android:textColor="@android:color/black"
android:textSize="18sp"
tools:text="Title"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toBottomOf="@+id/coverview"
app:layout_constraintLeft_toRightOf="@+id/native_ad_icon"/>
<TextView
android:id="@+id/native_ad_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@android:color/black"
android:textSize="15sp"
tools:text="des\ndes"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toBottomOf="@+id/native_ad_title"
app:layout_constraintLeft_toRightOf="@+id/native_ad_icon"/>
<TextView
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rating"
app:layout_constraintTop_toBottomOf="@+id/native_ad_body"
android:layout_marginLeft="10dp"
app:layout_constraintLeft_toRightOf="@+id/native_ad_icon"/>
<Button
android:id="@+id/call_to_action"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="DOWNLOAD NOW!"
android:textAllCaps="false"
android:layout_marginTop="10dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rating" />
<com.cloud.hisavana.sdk.api.view.PsMarkView
android:id="@+id/ps_mark_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/call_to_action"
app:layout_constraintEnd_toEndOf="parent" />
<com.cloud.hisavana.sdk.api.view.AdCloseView
android:id="@+id/hisavana_ad_close"
android:layout_width="20dp"
android:layout_height="20dp"
tools:ignore="MissingConstraints"
android:layout_margin="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
SDK changed com.cloud.hisavana.sdk.api.view.PsMarkView
to com.cloud.hisavana.sdk.api.view.StoreMarkView
on version 2.5.3.0
2.3.3.3 Initialize advertisement object
nativeAd = new TNative("native");
nativeAd.setListener(new AdListener() {
@Override
public void onMediaDownloaded(final TaNativeInfo ad) {
Log.d(TAG,"onMediaDownloaded");
}
@Override
public void onError(TaErrorCode adError) {
Log.e(TAG,"onError "+adError);
}
@Override
public void onAdLoaded(List<TaNativeInfo> adInfos1) {
adInfos = adInfos1;
Log.d(TAG,"onAdLoaded");
}
@Override
public void onAdShow() {
Log.d(TAG,"onAdShow");
}
@Override
public void onTimeOut() {
Log.d(TAG,"onTimeOut");
}
@Override
public void onAdClicked(DownUpPointBean pointBean) {
Log.d(TAG,"onAdClicked");
}
@Override
public void onBiddingSuccess(BidInfo bidInfo) {
//sdk2.0.1.1+New version, get price successfully
//nativeAd.loadAd(bidInfo);
}
});
2.3.3.4 Start requesting ads
After the advertisement is successfully requested, the onAdLoaded (List<TaNativeInfo> adInfos1)
method of advertisement listening will be recalled, as follows:
nativeAd.loadAd()
@Override
public void onLoad(List<TaNativeInfo> adInfos1) {
super.onLoad();
}
Note: The main image and title of the advertisement are required items. Others (such as advertisement icon, advertisement description, etc.) are optional. The media needs to adjust the layout according to whether the optional items have return values. For details, please refer to TaNativeInfo
2.3.3.5 Render advertisements
Render the advertisement after the advertisement request is successful.
- nativeAd.registerViews(nativeView, adContains, adNativeInfo); must be called correctly, otherwise it will affect the ad display statistics.
- When the ad space is icon type, there is no need to set the main image, but only the icon.
- If the SDK version is 2.2.0.0-2.3.1.4, you need to add psMarkView (app store logo), otherwise it will affect the jump link for downloading advertisements. If the connected sdk version is 2.5.3.0+, StoreMarkView (app store logo) needs to be added, otherwise it will affect the jump link for downloading advertisements
....
@Override
public void onLoad(List<TaNativeInfo> adInfos1) {
inflateView(adInfos1.get(0),nativeAd)
}
private void inflateView(TaNativeInfo adNativeInfo, TNative nativeAd) {
ConstraintLayout adView = (ConstraintLayout)LayoutInflater.from(this).inflate(R.layout.ad_unit, null);
ImageView icon = adView.findViewById(R.id.native_ad_icon);
MediaView mediaView = adView.findViewById(R.id.coverview);
AdChoicesView adChoicesView = adView.findViewById(R.id.ad_choice);
AdCloseView adCloseView = adView.findViewById(R.id.hisavana_ad_close);
TextView title = adView.findViewById(R.id.native_ad_title);
TextView des = adView.findViewById(R.id.native_ad_body);
Button calltoaction = adView.findViewById(R.id.call_to_action);
TextView rating = adView.findViewById(R.id.rating);
nativeView.destroy();
nativeView.addView(adView);
nativeView.setIconView(icon);
nativeView.setMediaView(mediaView, ImageView.ScaleType.FIT_XY);
nativeView.setAdChoiceView(adChoicesView);
//sdk2.1.0.2Added api, adCloseView is the close button
nativeView.setAdCloseView(adCloseView);
//sdk2.2.0.1Added api, psMarkView is the app store logo
nativeView.setPsMarkView(psMarkView);
title.setText(adNativeInfo.getTitle());
des.setText(adNativeInfo.getDescription());
calltoaction.setText(adNativeInfo.getCtatext());
if (!TextUtils.isEmpty(adNativeInfo.getRating())) {
rating.setText("R : " + adNativeInfo.getRating());
}
List<View> adContains = new ArrayList<>();
adContains.add(title);
adContains.add(icon);
adContains.add(mediaView);
adContains.add(calltoaction);
adContains.add(des);
adContains.add(adView);
adContains.add(adCloseView);
adContains.add(psMarkView);
nativeView.setupViews(adNativeInfo);//Before rendering native advertisements, sdk2.2.0.1 needs to be called
nativeAd.registerViews(nativeView, adContains, adNativeInfo);//Rendering native advertisements
,registering for listening
2.3.3.6 template rendering advertisement (sdk2.1.0.0+ support)
When setting the rendering method of the code bit id to template rendering on the media configuration platform, the following APIs need to be used to render the advertisement
nativeAd.registerViews(nativeView, adNativeInfo);
Media Configuration Platform Settings

template style fine-tuning api
TemplateStyle templateStyle;
if (isChangeStyle) {
templateStyle = new TemplateStyle.Builder()
.titleSize(20).titleColor(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_0051E1)).isTitleBold(0)
.descColor(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_0051E1)).descSize(20).isDescBold(1)
.callToAction_text_color(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_0051E1)).callToAction_text_isBold(1).callToAction_text_size(20)
.callToAction_background_color(CoreUtil.getContext().getResources().getColor(R.color.ad_button_bg_color))
.callToAction_corner_radius(0).callToAction_stroke_color(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_0051E1)).callToAction_stroke_width(5)
//.callToAction_background_shape(getResources().getDrawable(R.drawable.hisavana_bg_shadow))
//.callToAction_background_shape(getResources().getDrawable(R.drawable.item_background))
.background(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_787878))
.build();
} else {
templateStyle = new TemplateStyle.Builder().build();
}
nativeView.setTemplateStyle(templateStyle);
2.3.3.7 Close ad
@Override
public void onAdClosed() {
//This method will not be called back in native and banner ads, but will be called back when interstitial and open screen ads are closed.
}
@Override
public void onAdClosed(TaNativeInfo taNativeInfo) {
//Added in sdk2.1.0.0+ version, callback when clicking the close button of the ad, you can choose to call destroyShow() in the callback to destroy the ad,
//If used in the list, the position of the current advertisement in the list can be determined according to taNativeInfo, and dynamically deleted
if(null != tNativeView){
tNativeView.destroy();
taNativeInfo.destroy();
}
}
2.3.3.8 Destroy advertisements
@Override
protected void onDestroy() {
nativeView.destroy();
if (nativeAd != null) {
nativeAd.destroy();
}
super.onDestroy();
}
When an advertisement is used up, it can be destroyed and called mNativeInfo.release()
is OK.
2.3.3.9 Other APIs
adNativeInfo.isOfflineAd();
Note: To judge whether the filled advertisement belongs to offline or online advertisement, 1: offline advertisement 0: online advertisement -1: no filling.
nativeAd.setBidding(true)
nativeAd.loadAd()//These two APIs are used together to initiate bidding requests
nativeAd.loadAd(BidInfo bidInfo) //Initiate a material request after successful bidding
Note: The HeaderBidding function has been added to the SDK2.0.1.1+ version, and the above two APIs have been added.
2.3.4 Splash ADs
Brief introduction
The advertising style appearing at the natural endpoint and transition section supports advertising sizes of 9:16, 1:2 and 2:3, and the effect is shown in the figure:
9:16 | 1:2 | 2:3 |
---|---|---|
![]() | ![]() | ![]() |
Access steps
Splash supports displaying advertisements in two forms: View and Activity (SDK 2.2.0.1+support), and media can choose according to their own needs.
2.3.4.1 Add SplashView
First, add TSplashView to the layout file to display the open screen advertisement As follows(Advertisement display in View format):
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.cloud.hisavana.sdk.api.adx.TSplashView
android:id="@id/splash_ad"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="0dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
2.3.4.2 Initialize advertisement object
Advertisement displayed in View form
TSplashView splashView = findViewById(R.id.splash_ad);
splashView.setPlacementId(placementId);
Display ads in the form of Activity
TSplash tSplash = new TSplash(context,"placementId");
2.3.4.3 Set advertisement status monitor
Advertisement displayed in View form
splashView.setListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
Log.d(TAG,"onAdLoaded");
if (splashView != null){
splashView.show();
}
}
@Override
public void onAdClosed() {
super.onAdClosed();
Log.d(TAG,"onAdClosed");
}
@Override
public void onAdShow() {
super.onAdShow();
Log.d(TAG,"onAdShow");
}
@Override
public void onAdClicked(DownUpPointBean pointBean) {
super.onAdClicked(pointBean);
Log.d(TAG,"onAdClicked");
}
@Override
public void onError(TaErrorCode adError) {
super.onError(adError);
Log.d(TAG,"onError");
}
@Override
public void onAdChoiceClick() {
super.onAdChoiceClick();
Log.d(TAG,"onAdChoiceClick");
}
@Override
public void onBiddingSuccess(BidInfo bidInfo) {
//sdk2.0.1.1+New version, get price successfully
//splashView.loadAd(bidInfo);
}
});
Display ads in the form of Activity
tSplash.setListener(new AdListener)
2.3.4.4 Set skip listener
Advertisement displayed in View form
splashView.setSkipListener(new OnSkipListener() {
@Override
public void onClick() {
Log.d(TAG,"setSkipListener onClick");
}
@Override
public void onTimeEnd() {
Log.d(TAG,"setSkipListener onTimeEnd");
}
});
Regarding the processing method of jumping to the home page after clicking the open-screen advertisement: the developer needs to record the click state isClicked = true
in the onClicked()
callback in the startup page, and do the jump to the main page in the onResume()
method, Remove the logic processing of the screen-opening view.
…
@Override
public void onClicked() {
isClicked = true;
}
@Override
protected void onResume() {
super.onResume();
if (isClicked){
//Jump to the home page
guideToMain();
//Remove the open screen view
if (splashView!= null && splashView.getParent() != null){
((ViewGroup) splashView.getParent()).removeView(splashView);
}
}
}
…
Display ads in the form of Activity
tSplash.setSkipListener(new OnSkipListener())
2.3.4.5 Start requesting ads
Advertisement displayed in View form
splashView.loadAd();
Display ads in the form of Activity
tSplash.loadAd();
2.3.4.6 Display advertising
Advertisement displayed in View form
splashView.show();
Display ads in the form of Activity
tSplash.setLogoLayout(logoView);//Add logo
tSplash.show();
2.3.4.7 Close ad
@Override
public void onAdClosed() {
//This method will not be called back in native and banner ads, but will be called back when interstitial and open screen ads are closed.
}
@Override
public void onAdClosed() {
//Added in sdk2.1.0.0+ version, you can call splashView.destroy() to close the ad after the close is triggered
if(splashView != null){
splashView.destroy();
}
//When displaying advertisements in the form of activity, use the following APIs
if(tSplash != null){
tSplash.destroy();
tSplash = null;
}
}
2.3.4.8 Destroy advertisements
Advertisement displayed in View form
@Override
protected void onDestroy() {
super.onDestroy();
if (splashView != null) {
splashView.destroy();
splashView = null;
}
}
Display ads in the form of Activity
tSplash.destroy();
2.3.4.9 Other APIs
splashView.getFillAdType();
Note: To judge whether the filled advertisement belongs to offline or online advertisement, 1: offline advertisement 0: online advertisement -1: no filling.
splashView.setBidding(true)
splashView.loadAd()//These two APIs are used together to initiate bidding requests
splashView.loadAd(BidInfo bidInfo) //Initiate a material request after the auction is successful
Note: SDK2.0.1.1+ version adds the HeaderBidding function and the above two APIs