<br />

[Rewarded ads](https://support.google.com/admanager/answer/7386053) allow you to reward users with in-app items for interacting with video ads, playable ads, and surveys.

<br />

## Before you begin

Before you continue, do the following:

- [Set up Google Mobile Ads SDK (Legacy)](https://developers.google.com/ad-manager/mobile-ads-sdk/android/quick-start.md.txt).
- Use the test rewarded ad unit ID `/21775744923/example/rewarded`.
  - When building and testing your apps, make sure that you use test ads rather than live, production ads. If you don't use the test ad unit ID, Google can suspend your account.
  - Before you publish your app, replace this ID with your ad unit ID.
  - For details on Google Mobile Ads SDK (Legacy) test ads, see [Enable test ads](https://developers.google.com/ad-manager/mobile-ads-sdk/android/test-ads.md.txt).

## Load a rewarded ad object

> [!NOTE]
> **Note:** Make all calls to the Google Mobile Ads SDK (Legacy) on the main thread.

Rewarded ads are loaded by calling the static `load` method on the
`RewardedAd` class and passing in a `RewardedAdLoadCallback`. This is usually
done in the `onCreate` method of an `Activity`.
Notice that like other format load callbacks, `RewardedAdLoadCallback`
uses `LoadAdError` to provide higher fidelity error details.

### Java

```java
RewardedAd.load(
    this,
    "AD_UNIT_ID",
    new AdManagerAdRequest.Builder().build(),
    new RewardedAdLoadCallback() {
      @Override
      public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
        Log.d(TAG, "Ad was loaded.");
        MainActivity.this.rewardedAd = rewardedAd;
      }

      @Override
      public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
        Log.d(TAG, loadAdError.getMessage());
        rewardedAd = null;
      }
    });
```

### Kotlin

```kotlin
RewardedAd.load(
  this,
  "AD_UNIT_ID",
  AdManagerAdRequest.Builder().build(),
  object : RewardedAdLoadCallback() {
    override fun onAdLoaded(ad: RewardedAd) {
      Log.d(TAG, "Ad was loaded.")
      rewardedAd = ad
    }

    override fun onAdFailedToLoad(adError: LoadAdError) {
      Log.d(TAG, adError.message)
      rewardedAd = null
    }
  },
)
```

Replace <var class="readonly" translate="no">AD_UNIT_ID</var> with your ad unit ID.


> [!TIP]
> **Tip:** You can use ad load calls to build up a cache of preloaded ads before you intend to show them, so that ads can be shown with zero latency when needed. Because ads expire after an hour, you should clear this cache and reload with new ads every hour.

<br />

## Set the FullScreenContentCallback

The `FullScreenContentCallback` handles events related to displaying your
`RewardedAd`. Before you show your `RewardedAd`, make sure to set the callback
as follows:

### Java

```java
rewardedAd.setFullScreenContentCallback(
    new FullScreenContentCallback() {
      @Override
      public void onAdDismissedFullScreenContent() {
        // Called when fullscreen content is dismissed.
        Log.d(TAG, "Ad was dismissed.");
        // Don't forget to set the ad reference to null so you
        // don't show the ad a second time.
        rewardedAd = null;
      }

      @Override
      public void onAdFailedToShowFullScreenContent(AdError adError) {
        // Called when fullscreen content failed to show.
        Log.d(TAG, "Ad failed to show.");
        // Don't forget to set the ad reference to null so you
        // don't show the ad a second time.
        rewardedAd = null;
      }

      @Override
      public void onAdShowedFullScreenContent() {
        // Called when fullscreen content is shown.
        Log.d(TAG, "Ad showed fullscreen content.");
      }

      @Override
      public void onAdImpression() {
        // Called when an impression is recorded for an ad.
        Log.d(TAG, "Ad recorded an impression.");
      }

      @Override
      public void onAdClicked() {
        // Called when an ad is clicked.
        Log.d(TAG, "Ad was clicked.");
      }
    });
```

### Kotlin

```kotlin
rewardedAd?.fullScreenContentCallback =
  object : FullScreenContentCallback() {
    override fun onAdDismissedFullScreenContent() {
      // Called when fullscreen content is dismissed.
      Log.d(TAG, "Ad was dismissed.")
      // Don't forget to set the ad reference to null so you
      // don't show the ad a second time.
      rewardedAd = null
    }

    override fun onAdFailedToShowFullScreenContent(adError: AdError) {
      // Called when fullscreen content failed to show.
      Log.d(TAG, "Ad failed to show.")
      // Don't forget to set the ad reference to null so you
      // don't show the ad a second time.
      rewardedAd = null
    }

    override fun onAdShowedFullScreenContent() {
      // Called when fullscreen content is shown.
      Log.d(TAG, "Ad showed fullscreen content.")
    }

    override fun onAdImpression() {
      // Called when an impression is recorded for an ad.
      Log.d(TAG, "Ad recorded an impression.")
    }

    override fun onAdClicked() {
      // Called when an ad is clicked.
      Log.d(TAG, "Ad was clicked.")
    }
  }
```

## Show the ad

When you show a rewarded ad, use an `OnUserEarnedRewardListener` object
to handle reward events.

### Java

```java
rewardedAd.show(
    MainActivity.this,
    new OnUserEarnedRewardListener() {
      @Override
      public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
        Log.d(TAG, "User earned the reward.");
        // Handle the reward.
      }
    });
```

### Kotlin

```kotlin
rewardedAd?.show(
  this,
  OnUserEarnedRewardListener { rewardItem ->
    Log.d(TAG, "User earned the reward.")
    // Handle the reward.
    val rewardAmount = rewardItem.amount
    val rewardType = rewardItem.type
  },
)
```

For ads Google serves, Google Mobile Ads SDK (Legacy) calls the
[`onUserEarnedReward`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/OnUserEarnedRewardListener.md.txt#onUserEarnedReward(com.google.android.gms.ads.rewarded.RewardItem))
method before the
[`onAdDismissedFullScreenContent`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/FullScreenContentCallback.md.txt#onAdDismissedFullScreenContent())
method. For ads served with mediation, the third-party ad source
determines the callback order. For ad sources that provide a single close
callback with reward information, the mediation adapter calls the
`onUserEarnedReward` method before the `onAdDismissedFullScreenContent`
method. For details, see
[Set up mediation](https://developers.google.com/ad-manager/mobile-ads-sdk/android/mediation.md.txt).

## Optional: Validate server-side verification (SSV) callbacks

Apps that require extra data in server-side verification
callbacks should use the custom data feature of rewarded ads. Any string value
set on a rewarded ad object is passed to the `custom_data` query parameter of
the SSV callback. If no custom data value is set, the `custom_data` query
parameter value won't be present in the SSV callback.

The following code sample demonstrates how to set custom data on a rewarded ad
object before requesting an ad.

### Java

```java
RewardedAd.load(
    context,
    AD_UNIT_ID,
    new AdRequest.Builder().build(),
    new RewardedAdLoadCallback() {
      @Override
      public void onAdLoaded(RewardedAd ad) {
        rewardedAd = ad;
ServerSideVerificationOptions options =
new ServerSideVerificationOptions.Builder()
.setCustomData("SAMPLE_CUSTOM_DATA_STRING")
.build();
rewardedAd.setServerSideVerificationOptions(options);
      }
    });
```

### Kotlin

```kotlin
RewardedAd.load(
  context,
  AD_UNIT_ID,
  AdRequest.Builder().build(),
  object : RewardedAdLoadCallback() {
    override fun onAdLoaded(ad: RewardedAd) {
      rewardedAd = ad
val options =
ServerSideVerificationOptions.Builder().setCustomData("SAMPLE_CUSTOM_DATA_STRING").build()
rewardedAd?.setServerSideVerificationOptions(options)
}
},
)
```

Replace `SAMPLE_CUSTOM_DATA_STRING` with your custom
data.

If you want to set the custom reward string, you must do so before showing the
ad.

> [!IMPORTANT]
> **Key Point:** The custom reward string is [percent
> escaped](https://en.wikipedia.org/wiki/Percent-encoding) and might require decoding when parsed from the SSV callback.

## Examples on GitHub

- Rewarded ads example: [Java](https://github.com/googleads/googleads-mobile-android-examples/tree/main/java/admanager/RewardedVideoExample) \| [Kotlin](https://github.com/googleads/googleads-mobile-android-examples/tree/main/kotlin/admanager/RewardedVideoExample)

## Next steps

Explore the following topics:

- [User privacy](https://developers.google.com/ad-manager/mobile-ads-sdk/android/privacy.md.txt)
- [Optimized SDK initialization and ad loading
  (beta)](https://developers.google.com/ad-manager/mobile-ads-sdk/android/optimize-initialization)