# 3-2. Interstitial Ads

## Create an instance of the interstitial ad.

```java
private OAMInterstitial interstitial;
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
 
    interstitial = new OAMInterstitial( this );
}
```

## Set the placement ID for the interstitial ad

Apply the PLACEMENT ID issued from the ONE AdMax console as follows.

```java
interstitial.setPlacementId( PLACEMENT_ID );
```

## Request the interstitial ad

```java
interstitial.load();
```

{% hint style="danger" %}
Excessive calls to the `load()` API may lead to blocking.
{% endhint %}

## Display the interstitial ad

```java
interstitial.show();
```

## Specify the activity for displaying the interstitial ad

By default, interstitial ads are displayed in the Activity where the `load` API was called.\
If you want to display the interstitial ad in an Activity other than the one that called the `load` API, pass the Activity object as an argument to the `setCurrentActivity` method.

```java
interstitial.setCurrentActivity( activity );
```

## Check whether the interstitial ad has been loaded.

It is called to determine the availability of an ad when loading an interstitial ad.

```java
interstitial.isLoaded();
```

## Set the event listener for the interstitial ad.

Set a listener for events that occur when loading a interstial ad.

```java
interstital.setEventListener( new IOAMInterstitialEventListener(){
    @Override
    public void onLoaded(){                         // 전면 광고 loading 성공
        Log.d( Tag, "interstital load success" );
    }
 
    @Override
    public void onLoadFailed( OAMError error ){     // 전면 광고 loading 실패
        Log.d( Tag, "interstitial load failed " + error.toString() );
    }
 
    @Override
    public void onOpened(){                         // 전면 광고 open 성공
        Log.d( Tag, "interstital open success" );
    }
 
    @Override
    public void onOpenFailed( OAMError error ){     // 전면 광고 open 실패
        Log.d( Tag, "interstitial open failed " + error.toString() );
    }
 
    @Override
    public void onClosed( OAMCloseEvent event ){    // 전면 광고 종료
        // 전면 광고 닫기닫기 이벤트가 발생한 방법에 따라 closeEvent를 전달해 줍니다.
        // 단, 미디에이션 광고의 경우에는 확인할 수 없이 Unknown으로 전달됩니다.
 
        /* public enum OAMCloseEvent {
            UNKNOWN, CLICK_CLOSE_BTN, PRESSED_BACK_KEY, AUTO_CLOSE    
        }*/
 
        Log.d( Tag, "interstital closed " + event );
    }
 
    @Override
    public void onClicked(){                        // 전면 광고 클릭
        Log.d( Tag, "interstital clicked" );
    }
} );
```

{% content-ref url="../oamerror" %}
[oamerror](https://one-admax-organization.gitbook.io/one-admax-sdk/oneadmax_dev_guide_en/oamerror)
{% endcontent-ref %}

## Custom options for interstitial ads.

{% code fullWidth="false" %}

```java
BACKGROUND_COLOR            : 배경색 및 투명도 변경. Color 값
 
HIDE_CLOSE_BTN              : 우측 상단 닫기 버튼 노출 여부 설정. default : false
 
CLOSE_BTN_MARGIN_FROM_EDGE  : 중앙 광고 이미지를 기준으로 마진을 주고 싶은 경우 false로 변경하여 사용. default true.
CLOSE_BTN_LEFT_MARGIN       : 닫기 버튼 좌측 마진. default : -28dp
CLOSE_BTN_TOP_MARGIN        : 닫기 버튼 상단 마진. default : 20dp
CLOSE_BTN_RIGHT_MARGIN      : 닫기 버튼 우측 마진. default : 20dp
CLOSE_BTN_BOTTOM_MARGIN     : 닫기 버튼 하단 마진. default : 0
 
DISABLE_BACK_BTN            : 백키 종료 사용 안함. deault : false
 
IS_ENDING_AD                : 종료 메시지 노출 여부. default : false
ENDING_TEXT                 : 종료 메시지. default : "뒤로가기를 한 번 더 누르시면 종료됩니다."
ENDING_TEXT_SIZE            : 종료 메시지 size. default : 11sp
ENDING_TEXT_COLOR           : 종료 메시지 test color. default : white
ENDING_TEXT_GRAVITY         : 종료 메시지 gravity. default : RIGHT
```

{% endcode %}

## Sample code for interstitial ads.

```java
HashMap map = new HashMap<>();
map.put( OAMInterstitial.CustomExtraData.BACKGROUND_COLOR, Color.TRANSPARENT );
map.put( OAMInterstitial.CustomExtraData.DISABLE_BACK_BTN, true );
map.put( OAMInterstitial.CustomExtraData.HIDE_CLOSE_BTN, true );
 
// 전면광고를 Ending 배너로 사용하실 경우
map.put(OAMInterstitial.CustomExtraData.IS_ENDING_AD, true);
map.put(OAMInterstitial.CustomExtraData.ENDING_TEXT, "백키를 누르시면 종료됩니다. 감사합니다\n");
map.put(OAMInterstitial.CustomExtraData.ENDING_TEXT_SIZE, 14);
map.put(OAMInterstitial.CustomExtraData.ENDING_TEXT_COLOR, Color.parseColor("#ffffff"));
map.put(OAMInterstitial.CustomExtraData.ENDING_TEXT_GRAVITY, Gravity.RIGHT);
 
interstital.setCustomExtras( map );
interstital.load();
```
