> For the complete documentation index, see [llms.txt](https://docs.blueseasx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blueseasx.com/client-bidding/android/rewarded-ads.md).

# Rewarded Ads

### **Step1. Load**

On the BlueSea console, create client bidding placement for the ad request. Please note the client bidding placements don’t support floor price setup.

<div align="left"><img src="/files/n3vlomrKxCy6Lx6mgX68" alt=""></div>

Before requesting ads, please ensure that the SDK has been initialized.

To request rewarded video ads, declare a `MediationInfo` object. This object should include the ad mediation platform, the mediation version, and the BlueSea Adapter version used when requesting the ads. If you are integrating BlueSea SDK through your own mediation platform, it is recommended to declare the `MediationInfo` object and pass in the mediation information to facilitate monetization data management and channel monetization optimization. If you are integrating BlueSea SDK through third-party mediations like MAX, LevelPlay, etc., you can skip this step.

```
MediationInfo mediationInfo = new MediationInfo("<in house or mediation name>","<mediation-version-name>", "<adapter-version-code>");
```

* `<in house or mediation name>`: Pass the value as 'in-house' or the specific mediation platform name.
* `<mediation-version-name>`: Pass the version number of the mediation SDK.
* `<adapter-version-code>`: Pass the version number of the adapter.

Call the `loadRewardVideoAd()` method, pass the ad's Placement ID, and initiate the ad request:

```
BlueseasxSDK.loadRewordVideoAd("<BlueSea-pid>", mediationInfo, new AdLoadCallback<RewardVideoAd>() {
   @Override
   public void onAdLoadError(@NonNull AdError error) {
       Log.d(TAG, "loadRewordVideoAd error, code=" + error.getCode() + ", message=" + error.getMessage());
   }

   @Override
   public void onAdLoaded(@NonNull RewardVideoAd ad) {
       Log.d(TAG, "loadRewordVideoAd success");
       mRewardVideoAd = ad;
   }
});
```

`AdLoadCallback<RewardVideoAd>` callback:

* `onAdLoadError(AdError error)`: Indicates that no ads were filled. This may be due to the advertiser not bidding or other issues. You can check the error code and message using `AdError.getCode()` and `AdError.getMessage()`. For details on error codes, refer to [Test & Error Handling](/client-bidding/android/test-and-error-handling.md)
* `onAdLoaded(RewardVideoAd ad)`: Indicates that the ad was successfully filled and returns an instance of the `RewardVideoAd` object.

The following example shows how to fully load a rewarded video ad in the `onCreate()` method of an Activity:

```
...
import com.blueseasx.sdk.AdError;
import com.blueseasx.sdk.AdLoadCallback;
import com.blueseasx.sdk.RewardVideoAd;
import com.blueseasx.sdk.MediationInfo;
import com.blueseasx.sdk.RewardAdListener;

public class MainActivity extends Activity {

    RewardVideoAd mRewardVideoAd;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        ...
        MediationInfo mediationInfo = new MediationInfo("<in house or mediation name>","<mediation-version-name>", "<adapter-version-code>");
        BlueseasxSDK.loadRewordVideoAd("<BlueSea-pid>", mediationInfo, new AdLoadCallback<RewardVideoAd>() {
         @Override
         public void onAdLoadError(@NonNull AdError error) {
           Log.d(TAG, "loadRewordVideoAd error, pid=" + pid + ", code=" + error.getCode() + ", message=" + error.getMessage());
      }

       @Override
       public void onAdLoaded(@NonNull RewardVideoAd ad) {
         Log.d(TAG, "loadRewordVideoAd success");
         mRewardVideoAd = ad;
       }
     });
    }
}
```

### **Step2. Auction**

When you receive an `onAdLoaded(RewardVideoAd ad)` callback, use the `getPrice` method to get the price for this ad. (double type, unit: eCPM (USD) )

```
double price = RewardVideoAd.getPrice();
```

The client reports the auction result to BlueSea via the following two methods of RewardVideoAd:

```
// BlueSea win，then publisher pass the following info
* @param minBidder the bidder name of second highest price 
* @param auctionMinToWin Second-highest bid price, double type, unit: eCPM, rounded to 4 decimal places
*/
void notifyAdWin(@Nullable String minBidder, double auctionMinToWin
);

// BlueSea loss，then publisher pass the following info
* @param winBidder Winning bidder name — string
* @param auctionPrice Highest bid price — double, unit: eCPM, rounded to 4 decimal places
* @param auctionLossCode BlueSea loss reason — reason why BlueSea lost the auction
*/
void notifyAdLoss(@Nullable String winBidder, double auctionPrice,  int auctionLossCode
);
```

**Auction Loss Code**

<table data-header-hidden data-search="false"><thead><tr><th width="150.07421875"></th><th></th></tr></thead><tbody><tr><td><strong>Value</strong></td><td><strong>Definition</strong></td></tr><tr><td>1</td><td>Internal Error</td></tr><tr><td>2</td><td>Impression Opportunity Expired</td></tr><tr><td>9</td><td>Missing Bid Price</td></tr><tr><td>100</td><td>Bid was Below Auction Floor</td></tr><tr><td>102</td><td>Lost to Higher Bid</td></tr><tr><td>1000+</td><td>Publisher specific values; should be communicated with BlueSea beforehand.</td></tr></tbody></table>

### **Step3. Show**

After receiving the `onAdLoaded(RewardVideoAd ad)` callback, register the ad listener using the `RewardVideoAd.setAdListener()` method:

```
mRewardVideoAd.setAdListener(new RewardAdListener() {
    @Override
    public void onAdDisplayFailed(@NonNull AdError error) {
        // an error occurs when displaying the ad
    }

    @Override
    public void onAdDisplayed() {
        // an ad impression occurs
    }

    @Override
    public void onAdClicked() {
        // the ad is clicked by user
    }

    @Override
    public void onAdOpened() {
        // the ad overlays the screen
    }

    @Override
    public void onAdClosed() {
        // the ad is closed
    }

    @Override
    public void onAdRewarded() {
        // a reward can be granted
    }
});
```

Before displaying the ad, use the `RewardVideoAd.isExpired()` method to check if the ad has expired (the ad's validity period is typically 60 minutes). If the ad has expired, you can request a new one. If it has not expired, you can use the `RewardVideoAd.show(Activity activity)` method to display the rewarded video ad:

```
mRewardVideoAd.show(activity);
```

### **Step4. Destroy**

The SDK will automatically destroy the ad after detecting that the user has closed it.
