Rewarded interstitial is a type of incentivized ad format that lets you offer rewards for ads that appear automatically during natural app transitions. Unlike rewarded ads, users aren't required to opt in to view a rewarded interstitial.
Prerequisites
- Complete the Get started guide.
Always test with test ads
When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account.
The easiest way to load test ads is to use our dedicated test ad unit ID for Android rewarded interstitial ads:
/21775744923/example/rewarded-interstitial
It's been specially configured to return test ads for every request, and you're free to use it in your own apps while coding, testing, and debugging. Just make sure you replace it with your own ad unit ID before publishing your app.
For more information about how Next Gen Mobile Ads SDK test ads work, see Test Ads.
Load an ad
To load a rewarded interstitial ad, call the RewardedInterstitialAd
static
load()
method and pass in an AdLoadCallback<RewardedInterstitialAd>
to
receive the loaded ad or any possible errors.
Kotlin
import com.google.android.libraries.ads.mobile.sdk.common.AdLoadCallback
import com.google.android.libraries.ads.mobile.sdk.common.AdRequest
import com.google.android.libraries.ads.mobile.sdk.common.FullScreenContentError
import com.google.android.libraries.ads.mobile.sdk.common.LoadAdError
import com.google.android.libraries.ads.mobile.sdk.rewardedinterstitial.RewardedInterstitialAd
import com.google.android.libraries.ads.mobile.sdk.rewardedinterstitial.RewardedInterstitialAdEventCallback
import com.google.android.libraries.ads.mobile.sdk.MobileAds
class RewardedInterstitialActivity : Activity() {
private var rewardedInterstitialAd: RewardedInterstitialAd? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Load ads after you initialize
Next Gen Mobile Ads SDK
.
RewardedInterstitialAd.load(
AdRequest.Builder(AD_UNIT_ID).build(),
object : AdLoadCallback<RewardedInterstitialAd> {
override fun onAdLoaded(ad: RewardedInterstitialAd) {
// Rewarded interstitial ad loaded.
rewardedInterstitialAd = ad
}
override fun onAdFailedToLoad(adError: LoadAdError) {
// Rewarded interstitial ad failed to load.
rewardedInterstitialAd = null
}
},
)
}
companion object {
// Sample rewarded interstitial ad unit ID.
const val AD_UNIT_ID = "/21775744923/example/rewarded-interstitial"
}
}
Java
import com.google.android.libraries.ads.mobile.sdk.common.AdLoadCallback;
import com.google.android.libraries.ads.mobile.sdk.common.AdRequest;
import com.google.android.libraries.ads.mobile.sdk.common.FullScreenContentError;
import com.google.android.libraries.ads.mobile.sdk.common.LoadAdError;
import com.google.android.libraries.ads.mobile.sdk.rewardedinterstitial.RewardedInterstitialAd;
import com.google.android.libraries.ads.mobile.sdk.rewardedinterstitial.RewardedInterstitialAdEventCallback;
import com.google.android.libraries.ads.mobile.sdk.MobileAds;
class RewardedActivity extends Activity {
// Sample rewarded interstitial ad unit ID.
private static final String AD_UNIT_ID = "/21775744923/example/rewarded-interstitial";
private RewardedInterstitialAd rewardedInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load ads after you initialize
Next Gen Mobile Ads SDK
.
RewardedInterstitialAd.load(
new AdRequest.Builder(AD_UNIT_ID).build(),
new AdLoadCallback<RewardedInterstitialAd>() {
@Override
public void onAdLoaded(@NonNull RewardedInterstitialAd rewardedInterstitialAd) {
// Rewarded interstitial ad loaded.
AdLoadCallback.super.onAdLoaded(rewardedInterstitialAd);
RewardedActivity.this.rewardedInterstitialAd = rewardedInterstitialAd;
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError adError) {
// Rewarded interstitial ad failed to load.
AdLoadCallback.super.onAdFailedToLoad(adError);
rewardedInterstitialAd = null;
}
}
);
}
}
Set the RewardedInterstitialAdEventCallback
The RewardedInterstitialAdEventCallback
handles events related to displaying
your RewardedInterstitialAd
. Before showing the rewarded interstitial ad, make
sure to set the callback:
Kotlin
// Listen for ad events.
rewardedInterstitialAd?.adEventCallback =
object : RewardedInterstitialAdEventCallback {
override fun onAdShowedFullScreenContent() {
// Rewarded interstitial ad did show.
}
override fun onAdDismissedFullScreenContent() {
// Rewarded interstitial ad did dismiss.
rewardedInterstitialAd = null
}
override fun onAdFailedToShowFullScreenContent(
fullScreenContentError: FullScreenContentError
) {
// Rewarded interstitial ad failed to show.
rewardedInterstitialAd = null
}
override fun onAdImpression() {
// Rewarded interstitial ad did record an impression.
}
override fun onAdClicked() {
// Rewarded interstitial ad did record a click.
}
}
Java
// Listen for ad events.
rewardedInterstitialAd.setAdEventCallback(
new RewardedInterstitialAdEventCallback() {
@Override
public void onAdShowedFullScreenContent() {
// Rewarded interstitial ad did show.
RewardedInterstitialAdEventCallback.super.onAdShowedFullScreenContent();
}
@Override
public void onAdDismissedFullScreenContent() {
// Rewarded interstitial ad did dismiss.
RewardedInterstitialAdEventCallback.super.onAdDismissedFullScreenContent();
rewardedInterstitialAd = null;
}
@Override
public void onAdFailedToShowFullScreenContent(
@NonNull FullScreenContentError fullScreenContentError) {
// Rewarded interstitial ad failed to show.
RewardedInterstitialAdEventCallback.super.onAdFailedToShowFullScreenContent(
fullScreenContentError);
rewardedInterstitialAd = null;
}
@Override
public void onAdImpression() {
// Rewarded interstitial ad did record an impression.
RewardedInterstitialAdEventCallback.super.onAdImpression();
}
@Override
public void onAdClicked() {
// Rewarded interstitial ad did record a click.
RewardedInterstitialAdEventCallback.super.onAdClicked();
}
}
);
Show the ad
To show a rewarded interstitial ad, use the show()
method. Use an
OnUserEarnedRewardListener
object to handle reward events.
Kotlin
// Show the ad.
rewardedInterstitialAd?.show(
this@RewardedActivity,
object : OnUserEarnedRewardListener {
override fun onUserEarnedReward(rewardItem: RewardItem) {
// User earned the reward.
val rewardAmount = rewardItem.amount
val rewardType = rewardItem.type
}
},
)
Java
// Show the ad.
rewardedInterstitialAd.show(
RewardedActivity.this,
new OnUserEarnedRewardListener() {
@Override
public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
// User earned the reward.
int rewardAmount = rewardItem.getAmount();
String rewardType = rewardItem.getType();
}
});
Example
Download and run the example app that demonstrates the use of the Next Gen Mobile Ads SDK .