# Android용 배너 광고 유닛 API 마이그레이션

> SDK를 초기화하고, 특정 광고 유닛 ID로 배너 광고 오브젝트를 생성하고, 적응적 또는 고정 배너 크기를 설정하고, 로딩, 표시, 새로고침과 같은 광고 이벤트를 관리하기 위해 리스너를 구현하여 레벨플레이 배너 광고 유닛 API를 통합할 수 있습니다.

이 가이드에서는 현재 구현에서 레벨플레이 배너 API로 전환(광고 유닛 ID 사용)하여 배너 광고를 로드하고 표시하는 방법을 설명합니다.

## 필수 조건##prerequisites

* 최소 지원 SDK는 8.6.0입니다. 최신 SDK는 [여기](/grow/levelplay/sdk/android/sdk-integration.md)에서 다운로드할 수 있습니다.
* 레벨플레이 초기화 API 사용하여 SDK를 초기화해야 합니다.
* 레벨플레이 대시보드에서 AdUnitID를 찾습니다.

## 배너 광고 오브젝트 생성 및 크기 설정##create-banner-ad-object-and-set-size

배너 광고 오브젝트의 생성은 **onInitSuccess** 콜백을 수신한 후에 수행해야 합니다.

```java
// Create the banner view and set the ad unit id
LevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId");
```

```java
// Create the banner view and set the ad unit id
val levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId")
```

### 배너 크기##banner-sizes

| **레거시**          | **광고 단위 이름(새로운)**     | dp의 **크기**                                         |
| ---------------- | --------------------- | -------------------------------------------------- |
| **ISBannerSize** | **LevelPlayAdSize**   | **(너비 X 높이)**                                      |
| 배너               | 배너                    | 320 x 50                                           |
| 대규모              | 대규모                   | 728 x 90                                           |
| 직사각형             | MEDIUM\_RECTANGLE     | 300 x 250                                          |
| SMART            | 적응적 광고 크기로 대체됨(아래 참조) | 모바일 및 태블릿의 크기 및 방향, 방향 설정 조정하기 위해 광고를 자동으로 렌더링합니다. |

광고 크기를 생성하려면 다음 옵션 중 하나를 따르십시오. 

**화면 너비에 맞게 조정되는 적응적 광고 크기(권장):** 이 옵션은 기기 유형에 따라 배너 또는 LEADERBOARD를 반환합니다. 적응적 기능을 지원하는 네트워크(Google, Yandex)는 최적화 로직에 따라 높이를 반환합니다.

```java
 LevelPlayAdSize adSize = LevelPlayAdSize.createAdaptiveAdSize(context);
```

```java
 val adSize = createAdaptiveAdSize(context)
```

**특정 배너 크기:** 이 옵션을 사용하면 배너 크기를 구체적으로 설정할 수 있습니다. BANNER, LARGE, MEDIUM\_RECTANGLE.

```java
levelPlayBanner.setAdSize(LevelPlayAdSize.MEDIUM_RECTANGLE);
```

```java
levelPlayBanner.setAdSize(LevelPlayAdSize.MEDIUM_RECTANGLE) 
```

### Placements##placements

우리는 보고만을 위한 배너에 있는 [플레이스먼트를](/grow/levelplay/platform/settings/placements.md) 지원합니다. 모든 재로드된 광고에 영향을 주기 위해 플레이스먼트는 **loadAd** 이전에 설정해야 합니다.

```java
// Set the placement name
levelPlayBanner.setPlacementName("placementName");
```

```java
// Set the placement name
levelPlayBanner.setPlacementName("placementName")
```

## 배너 리스너 설정##set-banner-listener

리스너 **LevelPlayBannerListener** 대신 코드에 **LevelPlayBannerAdViewListener를 구현**합니다.

* 배너 광고를 로드하기 전에 리스너를 설정하는 것이 좋습니다.
* 각 배너 광고에는 자체 리스너 구현이 있어야 합니다.
* 콜백은 메인 스레드 실행됩니다.

```java
levelPlayBanner.setBannerListener(new LevelPlayBannerAdViewListener() {
    @Override
    public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) {
    // Ad was loaded successfully 
    }
    @Override
    public void onAdLoadFailed(@NonNull LevelPlayAdError error) {
    // Ad load failed
    }
    @Override
    public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) {
    // Ad was displayed and visible on screen
    }
    @Override
    public void onAdDisplayFailed(@NonNull LevelPlayAdInfo adInfo, @NonNull LevelPlayAdError error) {
    // Ad failed to be displayed on screen
    }
    @Override
    public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) {
    // Ad was clicked
    }
    @Override
    public void onAdExpanded(@NonNull LevelPlayAdInfo adInfo) {
    // Ad is opened on full screen
    }
    @Override
    public void onAdCollapsed(@NonNull LevelPlayAdInfo adInfo) {
    // Ad is restored to its original size
    }
    @Override
    public void onAdLeftApplication(@NonNull LevelPlayAdInfo adInfo) 
    // User pressed on the ad and was navigated out of the app 
    }
);
```

```java
levelPlayBanner.setBannerListener(object: LevelPlayBannerAdViewListener {
    override fun onAdLoaded(adInfo: LevelPlayAdInfo) {
    // Ad was loaded successfully 
    }
    오버라이드 fun onAdLoadFailed(오류: LevelPlayAdError) {
    // Ad load failed
    }
    override fun onAdDisplayed(adInfo: LevelPlayAdInfo) {
    // Ad was displayed and visible on screen
    }
    override fun onAdDisplayFailed(adInfo: LevelPlayAdInfo, error: LevelPlayAdError) {
    // Ad failed to be displayed on screen
    }
    override fun onAdClicked(adInfo: LevelPlayAdInfo) {
    // Ad was clicked
    }
    override fun onAdExpanded(adInfo: LevelPlayAdInfo) {
    // Ad is opened on full screen
    }
    override fun onAdCollapsed(adInfo: LevelPlayAdInfo) {
    // Ad is restored to its original size
    }
    override fun onAdLeftApplication(adInfo: LevelPlayAdInfo) {
    // User pressed on the ad and was navigated out of the app 
    }
})
```

|    | 레거시                     | 광고 단위(신규)                     |
| -- | ----------------------- | ----------------------------- |
| 청자 | LevelPlayBannerListener | LevelPlayBannerAdViewListener |
| 콜백 | onAdLoaded              | onAdLoaded                    |
|    | onAdLoadFailed          | onAdLoadFailed                |
|    | onAdClicked             | onAdClicked                   |
|    | onAdScreenPresented     | onAdExpanded                  |
|    | onAdScreenDismissed     | onAdCollapsed                 |
|    | onAdLeftApplication     | onAdLeftApplication           |
|    |                         | onAdDisplayed                 |
|    |                         | onAdDisplayFailed             |

### 레벨플레이 광고 정보##levelplay-ad-info

배너 리스너 콜백이 반환하는 **AdInfo** 클래스가 **LevelPlayAdInfo**로 대체되었습니다.

## 배너 광고 로드##load-banner-ad

배너 광고를 로드하려면 **IronSource.loadBanner** 대신 **loadAd를** 사용하십시오.

```java
// Load the banner ad
levelPlayBanner.loadAd();
```

```java
// Load the banner ad
levelPlayBanner.loadAd()
```

## 배너 새로고침 일시 정지 및 재개##pause-and-resume-banner-refresh

새로고침 값이 플랫폼에서 정의된 경우 코드에서 배너 새로고침을 일시 정지할 수 있습니다. 배너 광고의 자동 새로고침을 중지하거나, 일시 중지한 후 다시 활성화하다, 사용 가능하다. 

> **Note:**
>
> 배너 다시 표시되면 배너가 일시 정지된 시점부터 새로고침까지의 시간을 완료합니다. 

* **pauseAutoRefresh** - 배너 광고의 자동 새로고침을 일시 중지합니다.
* **resumeAutoRefresh** - 배너 광고가 일시 중지된 후 배너 광고의 자동 새로고침을 재개합니다.

```java
// Pause refresh
levelPlayBanner.pauseAutoRefresh();
// Resume refresh
levelPlayBanner.resumeAutoRefresh();
```

```java
// Pause refresh
levelPlayBanner.pauseAutoRefresh()
// Resume refresh
levelPlayBanner.resumeAutoRefresh()
```

## 배너 광고 삭제##destroy-banner-ad

배너를 파괴하려면 **IronSource.destroyBanner** 대신 **파괴** 메서드를 호출합니다.

삭제된 배너 더 이상 표시할 수 없습니다. 더 많은 광고를 표시하려면 새 **LevelPlayBannerAdView** 오브젝트를 만드십시오. 

```java
levelPlayBanner.destroy()
```

```java
levelPlayBanner.destroy();
```

## 여러 광고 유닛 배너 API##multiple-ad-unit-banner-apis

|         | 레거시                    | 광고 단위(신규)                 |
| ------- | ---------------------- | ------------------------- |
| 배너 레이아웃 | IronSourceBannerLayout | LevelPlayBannerAdView     |
| API     | loadBanner             | loadAd                    |
|         | destroyBanner          | destroy                   |
|         | loadBanner             | setPlacementName          |
|         | -                      | LevelPlayAdSize.getWidth  |
|         | -                      | LevelPlayAdSize.getHeight |
|         | -                      | pauseAutoRefresh          |
|         | -                      | resumeAutoRefresh         |

## 배너 광고의 전체 구현 예시##full-implementation-example-of-banner-ads

다음은 적응적 배너 크기를 사용하여 배너 광고를 생성하고 로드하는 예제입니다.

```java
public void createAndLoadBanner() {
    // Create the banner view and set the ad unit id
    LevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId");
    
    // Set the placement name (optional)
    levelPlayBanner.setPlacementName("placementName");
    
    // Create the adaptive ad size to support both adaptive, banner and leaderboard (recommended)  
    LevelPlayAdSize adSize = LevelPlayAdSize.createAdaptiveAdSize(context);
    
    // Required when using createAdaptiveAdSize()
    if (adSize != null) {
        levelPlayBanner.setAdSize(adSize);
    }
    
    // Add the banner view to the container
    ViewGroup adContainer = findViewById(android.R.id.adContainer);
    adContainer.addView(levelPlayBanner);
    
    // Load the banner ad
    levelPlayBanner.loadAd();
    
    // To get actual banner layout size (either custom/standard size or adaptive)
    height = adSize.getHeight();
    width = adSize.getWidth();
}
```

```java
fun createAndLoadBanner() {
    // Create the banner view and set the ad unit id
    val levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId")
    
    // Set the placement name
    levelPlayBanner.setPlacementName("placementName")
    
    // Create the adaptive ad size to support both adaptive, banner and leaderboard
    val adSize = createAdaptiveAdSize(context)
    
    // Required when using createAdaptiveAdSize()
    adSize?.let { levelPlayBanner.setAdSize(it) }
    
    // Add the banner view to the container
    val adContainer = findViewById<ViewGroup>(R.id.adContainer)
    adContainer.addView(levelPlayBanner)
    
    // Load the banner ad
    levelPlayBanner.loadAd()
    
    // Get width and height for the container
    val width = adSize?.getWidth()
    val height = adSize?.getHeight()
}
```

## 레벨플레이 Mediation 데모 앱##levelplay-mediation-demo-app

통합 데모 애플리케이션 앱에 배너 배너 유닛 API를 통합하는 방법을 보여 줍니다.

[Android 데모 애플리케이션 다운로드](https://github.com/ironsource-mobile/Mediation-Demo-Apps)
