# 3-1. Rewarded Video Ads

## UserID Settings <a href="#id-01.sdk-userid" id="id-01.sdk-userid"></a>

It is used to identify the user for rewarding them upon completion of the rewarded video.

```java
ONEAdMax.setUserId( context, UserID );
```

{% hint style="warning" %}

* Each user must have a unique user identifier, which should not be a variable value.
* It must not include personal information such as email, name, phone number, or identifiable user IDs.
* If it contains Korean characters, special characters, or spaces, it must be URL encoded before use.
* The user identifier must be set before the user enters the ad.
  {% endhint %}

## Creating a Rewarded Video Ad Instance

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

## Setting the Rewarded Video Ad Placement ID

Make sure to replace `"your_placement_id"` with the actual placement ID you received from the ONE AdMax console.

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

## Setting the Network Timeout for Rewarded Video Ad Request

Set the network timeout for the rewarded video ad request. When loading the rewarded video ad, a timeout is given for each ad network (mediation provider). If the ad is not received within the specified timeout, the request will move on to the next  ad network.

```java
rewardVideo.setNetworkScheduleTimeout( 10 ); // default 10 sec
```

## Reward Video Load

You can request the rewarded video ad from the server by calling the `Load()` API.

```java
rewardVideo.load();
```

{% hint style="danger" %}
Excessive calls to the `load()` API may result in being blocked.
{% endhint %}

## Reward Video Show <a href="#id-01.sdk" id="id-01.sdk"></a>

Once the ad loading is complete, you can display the ad by calling the `show()` API at the desired point in your application:

```java
rewardVideo.show();
```

To specify the Activity for displaying the rewarded video ad, you need to set it when calling the `show()` method.

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

To check whether the rewarded video ad has been successfully loaded, you can use the following method:

```java
rewardVideo.isLoaded();
```

To set up an event listener for the rewarded video ad, you can use the following approach:

```java
rewardVideo.setEventListener( new IOAMRewardVideoEventListener(){
    @Override
    public void onLoaded(){                         // 리워드 비디오 광고 loading 성공
        Log.d( Tag, "rewardVideo load success" );
    }
 
    @Override
    public void onLoadFailed( OAMError error ){     // 리워드 비디오 광고 loading 실패
        Log.d( Tag, "rewardVideo load failed " + error.toString() );
    }
 
    @Override
    public void onOpened(){                         // 리워드 비디오 광고 open 성공
        Log.d( Tag, "rewardVideo open success" );
    }
 
    @Override
    public void onOpenFailed( OAMError error ){     // 리워드 비디오 광고 open 실패
        Log.d( Tag, "rewardVideo open failed " + error.toString() );
    }
 
    @Override
    public void onClosed(){                         // 리워드 비디오 광고 종료
        Log.d( Tag, "rewardVideo closed " + event );
    }
 
    @Override
    public void onClicked(){                        // 리워드 비디오 광고 클릭. 일부 미디에이션 광고는 지원 안함
        Log.d( Tag, "rewardVideo clicked" );
    }
 
    @Override
    public void onCompleted( int adNetworkNo, boolean completed ){ // 리워드 비디오 광고 완료. on completed 에서 completed 가 true 일 때만 리워드 지급
        Log.d( Tag, "rewardVideo  completed " + completed  );
    }
 
} );
```

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

## Call the CS page.

This is the API to call the rewarded video ad CS page. You need to pass the Activity context in order for the page to be displayed correctly.

```java
ONEAdMax.openRewardVideoCSPage( Activity activity, String userID )
```

\
Here’s a sample code for integrating a rewarded video ad in your app:

```java
private OAMRewardVideo rewardVideo;
 
@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.");      
                initRewardVideo( yourRewardPlacementID );
            }
        });
    }
 
    ...
}
 
 
public void initRewardVideo( String yourPlacementId ){
    rewardVideo = new  OAMRewardVideo( this );
 
    // placementID는 필수입니다.
    rewardVideo.setPlacementId( yourPlacementId );
 
    // optional   
    rewardVideo.setNetworkScheduleTimeout( 10 ); 
 
    // listener를 등록하지 않으면 이벤트를 받을 수 없습니다.
    rewardVideo.setEventListener( new IOAMRewardVideoEventListener(){
        @Override
        public void onLoaded(){                         // 리워드 비디오 광고 loading 성공
            Log.d( Tag, "rewardVideo load success" );
            // loading 성공 이후, showing.
            rewatdVideo.show();
        }
 
        @Override
        public void onLoadFailed( OAMError error ){     // 리워드 비디오 광고 loading 실패
          Log.d( Tag, "rewardVideo load failed " + error.toString() );
        }
 
        @Override
        public void onOpened(){                         // 리워드 비디오 광고 open 성공
            Log.d( Tag, "rewardVideo open success" );
        }
 
        @Override
        public void onOpenFailed( OAMError error ){     // 리워드 비디오 광고 open 실패
          Log.d( Tag, "rewardVideo open failed " + error.toString() );
        }
     
        @Override
        public void onClosed(){                         // 리워드 비디오 광고 종료
            Log.d( Tag, "rewardVideo closed " + event );
        }
 
        @Override
        public void onClicked(){                        // 리워드 비디오 광고 클릭. 일부 미디에이션 광고는 지원 안함
            Log.d( Tag, "rewardVideo clicked" );
        }
 
        @Override
        public void onCompleted( int adNetworkNo, boolean completed ){ // 리워드 비디오 광고 완료
            Log.d( Tag, "rewardVideo completed. " + completed );
        } 
    } );
 
    rewardVideo.load();
}
 
 
 
@Override
protected void onDestroy(){
    super.onDestroy();
    ONEAdMax.unInit();
}
```

## Mediation Settings <a href="#id-01.sdk" id="id-01.sdk"></a>

For stable fill rate and eCPM, it is recommended to integrate mediation with AppLovin, Unity Ads, and Vungle. These networks can help maximize ad revenue by providing a broad range of ad inventory, improving ad fill rates, and optimizing eCPM.

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