3-3. Banner Ads

A banner is the most common form of advertising, displayed as a strip at the top or bottom of an app.

Create a banner ad.

Banner ads can be implemented either declaratively or imperatively.

XML declarative method.

Add the view where the banner ad will be displayed to the Layout.xml file in use.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:orientation="vertical"> 
        <!-- Banner View -->         
       <com.oneadmax.global.OAMBanner
            android:id="@+id/banner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
</LinearLayout>

Add the instance formed in XML to the code.

private OAMBanner banner;
 
@Override
protected void onCreate( Bundle savedInstanceState ){
    ...
    banner = (OAMBanner)findViewById(R.id.banner);
    ...
}

Imperative (code) method.

Without using XML, you can create a banner ad through the source code context using commands.

private OAMBanner banner;
 
@Override
protected void onCreate( Bundle savedInstanceState ){
    ...
    // 베너 광고가 보이게 될 Activity와, 상단 또는 하단에 생성할지를 전달합니다.
    banner = new OAMBanner( MyActivity.this, Gravity.TOP|Gravity.CENTER );
    ...
}

Set the banner PLACEMENT ID.

The banner PLACEMENT ID can be created in the ONE AdMax console.

banner.setPlacementId( PLACEMENT_ID );

Banner Size

There are three banner size options, and the value specified when creating the banner ad in the ONE AdMax console must be set accordingly.

public enum Size {
    BANNER_320x50, BANNER_300x250, BANNER_320x100,
}
 
banner.setSize( OAMBanner.Size.BANNER_320x50 );

The configurable range is 15 to 300 seconds, and setting it to -1 disables the refresh.

banner.setRefreshTime( 60 ); // default 60 sec

When loading banner ads, a timeout is set for each network (mediation partner). If an ad is not received within the specified time, it moves on to the next network.

banner.setNetworkScheduleTimeout( 5 ); // default 5 sec
public enum AnimType{
    NONE,          
    FADE_IN,       
    SLIDE_LEFT,    
    SLIDE_RIGHT,
    TOP_SLIDE,
    BOTTOM_SLIDE,
    CIRCLE,
}
 
banner.setAnimType( OAMBanner.AnimType.FADE_IN ); // default : NONE

You can fill the empty space in the view where the banner ad appears with an optimized background color that matches the ad.

banner.setAutoBgColor( true );  // default true

The load() API is called at the desired point when the banner should appear on the screen. Once the loading is complete, the onLoaded() event is triggered, and the banner will automatically appear on the screen.

banner.load();

Excessive calls to the load() API will result in a block.

This is called when you want to stop the banner ad. Typically, it is called when the activity or fragment displaying the banner is destroyed.

banner.stop();

Calling stop() when entering the onPause state may lead to missing click report data. Therefore, it is recommended to call it when the activity or fragment containing the banner view is destroyed.

Unlike other ad types, banners are automatically displayed on the screen once they are loaded. Therefore, you can use the following API to determine whether the banner is visible or not.

banner.isLoaded();

Set up listeners for events that occur when loading a banner. The provided listeners and implementation examples are as follows:

banner.setEventListener( new IOAMBannerEventListener(){
    @Override
    public void onLoaded(){                     // banner loading 성공
        Log.d( Tag, "onBannerAdLoaded" );
    }
 
    @Override
    public void onLoadFailed( OAMError error ){ // banner loading 실패
        Log.d( Tag, "onLoadFailed : " + error.toString() );
    }
     
    @Override
    public void onClicked(){                    // banner click.
        Log.d( Tag, "onBannerAdLoaded" );
    }
});

Banner onPause / onResume

In the onPause / onResume of the Activity or Fragment where the banner ad is displayed, you should call the banner's onPause / onResume. If onPause / onResume is not handled correctly, there may be missing report data when using third-party mediation. Therefore, it is recommended to implement it as shown below.

OAMBanner   banner;
 
public void onPause(){
    super.onPause();
 
    if( banner != null )
        banner.onPause();
}
 
public void onResume(){
    super.onResume();
 
    if( banner != null )
        banner.onResume();
}

Banner Mediation

Banner ads support the use of some mediation platforms. The settings must be configured before calling the banner's load() API.

HashMap map = new HashMap<>();
map.put( OAMBanner.MediationExtra.CAULY_USE_DYNAMIC_RELOAD, false );
map.put( OAMBanner.MediationExtra.CAULY_RELOAD_INTERVAL, 20 );
map.put( OAMBanner.MediationExtra.CAULY_THREAD_PRIORITY, 5 );
 
banner.setMediationExtras( map );
banner.load();

The configuration values for supported mediations are as follows:

CAULY_ENABLE_LOCK               : 잠금 화면에서 노출 가능 여부. default false.
CAULY_ENABLE_DYNAMIC_RELOAD_INTERVAL: 카울리 다이나믹 배너 갱신 사용 여부. default true.
CAULY_RELOAD_INTERVAL           : 카울리 배너 갱신 주기. range: 10~120. default 20s. CAULY_ENABLE_DYNAMIC_RELOAD_INTERVAL를 false로 설정후에 사용가능.
CAULY_THREAD_PRIORITY           : 카울리 스레드 우선 순위 지정. range: 1~10. default 5.
 
MEZZO_AGE_LEVEL                 : 유저 나이 정보, default -1. 알수 없음 = -1, 어린이(13세 미만) = 0, 청소년 및 성인(만 13세 이상) = 1
MEZZO_ENABLE_BACKGROUND_CHECK   : 백그라운드 갱신 사용 여부.
MEZZO_STORE_URL                 : 앱 스토어 URL

Banner sample code

private OAMBanner banner;
 
@Override
protected void onCreate( Bundle savedInstanceState ){
    super.onCreate( savedInstanceState );
    ...
     
    // ONEAdMax 로그 활성화. apk release시에는 삭제해야 합니다.
    ONEAdMax.setLogEnable( true );
 
    //ONEAdMax SDK 초기화
    if( ONEAdMax.isInit( MyActivity.this ) == false ){
        ONEAdMax.init( MyActivity.this, new IOAMInitListener() {
            @Override
            public void onInitialized() {
                Log.d( Tag, "ONEAdMax SDK Initialized.");
                initBanner( yourBannerPlacementID,  youtBannerSize  );
            }
        });
    }
 
    ...
}
 
 
public void initBanner( String placementId, OAMBanner.Size bannerSize ){
    // xml 없이 코드로 Banner 를 생성합니다.
    banner = new OAMBanner( MyActivity.this, Gravity.TOP|Gravity.CENTER );
 
    // placementID와 size setting은 필수입니다.  
    banner.setPlacementId( yourBannerPlacementID );
    banner.setSize( bannerSize );
 
    // optional    
    banner.setAnimType( OAMBanner.AnimType.FADE_IN );
    banner.setAutoBgColor( true );    
    banner.setNetworkScheduleTimeout( 10 );
    banner.setRefreshTime( 15 );
   
    HashMap map = new HashMap<>();
    map.put( OAMBanner.MediationExtra.CAULY_USE_DYNAMIC_RELOAD, false );
    map.put( OAMBanner.MediationExtra.CAULY_RELOAD_INTERVAL, 20 );
    map.put( OAMBanner.MediationExtra.CAULY_THREAD_PRIORITY, 5 );
    banner.setMediationExtras( map ); 
 
 
    // listener를 등록하지 않으면 이벤트를 받을 수 없습니다.
    banner.setEventListener( new IOAMBannerEventListener(){
        @Override
        public void onLoaded(){
            Log.d( Tag, "banner load success" );
        }
 
        @Override
        public void onLoadFailed( OAMError error ){
            Log.d( Tag, "banner load failed: " + error.toString() );
        }
 
        @Override
        public void onClicked(){
            Log.d( Tag, "banner clicked." );
        }
    } );    
 
    banner.load();
}
 
@Override
public void onPause(){
    super.onPause();
 
    if( banner != null )
        banner.onPause();
}
 
@Override
public void onResume(){
    super.onResume();
 
    if( banner != null )
         banner.onResume();
}
 
@Override
protected void onDestroy(){
    super.onDestroy();  
     
    if( banner != null )
        banner.stop();
 
    ONEAdMax.unInit();
}

Last updated