Rewarded Ads Integration for Android
The Unity LevelPlay Rewarded is a full-screen ad unit, usually served at natural transition points during the app lifecycle.
- Make sure that you have correctly integrated the ironSource SDK into your application. Integration is outlined here.
- Make sure to initialize the SDK using LevelPlay Initialization API.
- You can find the AdUnitID in LevelPlay dashboard. Learn more here.
- This documentation is relevant for SDK 8.5.0+. Documentation for legacy Rewarded APIs (SDK 8.5.0 and below) can be found here.
Create Rewarded Ad Object
The creation of the Rewarded ad object must be performed after receiving the onInitSuccess callback.
The object is a reusable instance that can handle multiple loads and shows throughout the session. Once created, it should be used to load and show ads for the same ad unit.
For more advanced implementations, you may create multiple Rewarded ad objects if necessary.
LevelPlayRewardedAd mRewardedAd = new LevelPlayRewardedAd("adUnitId");
val mRewardedAd = LevelPlayRewardedAd("adUnitId")
Set Rewarded Listener
Implement the LevelPlayRewardedAdListener in your code to get informed of ad delivery.
- It is recommended to set the listener before loading the Rewarded ad.
- Please note that each Rewarded ad should have its own listener implementation.
- Callbacks run on the main thread.
// Create the Rewarded ad object
LevelPlayRewardedAd mRewardedAd = new LevelPlayRewardedAd("adUnitId");
mRewardedAd.setListener(new LevelPlayRewardedAdListener() {
@Override
public void onAdLoaded(LevelPlayAdInfo levelPlayAdInfo) {
// Ad was loaded successfully
}
@Override
public void onAdLoadFailed(LevelPlayAdError levelPlayAdError) {
// Ad load failed
}
@Override
public void onAdDisplayed(LevelPlayAdInfo levelPlayAdInfo) {
// Ad was displayed and visible on screen
}
@Override
public void onAdRewarded(@NonNull LevelPlayReward reward, @NonNull LevelPlayAdInfo adInfo) {
// Ad reward received
}
@Override
public void onAdDisplayFailed(LevelPlayAdError levelPlayAdError, LevelPlayAdInfo levelPlayAdInfo) {
// Ad fails to be displayed
// Optional
}
@Override
public void onAdClicked(LevelPlayAdInfo levelPlayAdInfo) {
// Ad was clicked
// Optional
}
@Override
public void onAdClosed(LevelPlayAdInfo levelPlayAdInfo) {
// Ad was closed
// Optional
}
@Override
public void onAdInfoChanged(LevelPlayAdInfo levelPlayAdInfo) {
// Called after the ad info is updated. Available when another Rewarded ad has loaded, and includes a higher CPM/Rate
// Optional
}
});
// Create the Rewarded ad object
val mRewardedAd = LevelPlayRewardedAd("adUnitId")
mRewardedAd.setListener(object : LevelPlayRewardedAdListener {
override fun onAdLoaded(levelPlayAdInfo: LevelPlayAdInfo) {
// Ad was loaded successfully
}
override fun onAdLoadFailed(levelPlayAdError: LevelPlayAdError) {
// Ad load failed
}
override fun onAdDisplayed(levelPlayAdInfo: LevelPlayAdInfo) {
// Ad was displayed and visible on screen
}
override fun onAdRewarded(reward: LevelPlayReward, adInfo: LevelPlayAdInfo) {
// Ad reward received
}
override fun onAdDisplayFailed(levelPlayAdError: LevelPlayAdError, levelPlayAdInfo: LevelPlayAdInfo) {
// Ad fails to be displayed
// Optional
}
override fun onAdClicked(levelPlayAdInfo: LevelPlayAdInfo) {
// Ad was clicked
// Optional
}
override fun onAdClosed(levelPlayAdInfo: LevelPlayAdInfo) {
// Ad was closed
// Optional
}
override fun onAdInfoChanged(levelPlayAdInfo: LevelPlayAdInfo) {
// Called after the ad info is updated. Available when another Rewarded ad has loaded, and includes a higher CPM/Rate
// Optional
}
})
LevelPlay Ad Info
The LevelPlayAdInfo parameter includes information about the loaded ad.
Learn more about its implementation and available fields here.
Load Rewarded Ad
To load an Rewarded ad use loadAd.
Show Rewarded Ad
Show an Rewarded ad after you receive the onAdLoaded callback using the LevelPlayRewardedAdListener APIs.
- It is required to share Activity.
- If using placements, pass the placement name in the showAd API as shown in the Placements section below.
- Once the ad has been successfully displayed to the user, you can load another ad by repeating the loading step.
public void showRewardedAd() {
// Check that ad is ready
if (mRewardedAd.isAdReady()) {
// Show ad
mRewardedAd.showAd(this);
}
}
fun showRewardedAd() {
// Check that ad is ready
if (mRewardedAd.isAdReady()) {
// Show ad
mRewardedAd.showAd(this)
}
}
Check Ad is Ready
To avoid show failures, and to make sure the ad could be displayed correctly, we recommend using the following API before calling the showAd API.
isAdReady – returns true if ad was loaded successfully and ad unit is not capped, or false otherwise.
isPlacementCapped – returns true when a valid placement is capped. If the placement is not valid, or not capped, this API will return false.
// Check that ad is ready and that the placement is not capped
if (mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) {
mRewardedAd.showAd(this, placementName);
}
// Check that ad is ready and that the placement is not capped
if (mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) {
mRewardedAd.showAd(this, placementName)
}
Placements
We support placements pacing and capping for Rewarded on the LevelPlay dashboard.
If placements are set up for Rewarded ads, call the showAd method to serve the ad for a specific placement.
public void showRewardedAdWithPlacement() {
// Check that ad is ready and that the placement is not capped
if (mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) {
// Show ad with placement
mRewardedAd.showAd(this, placementName);
}
}
fun showRewardedAdWithPlacement(placementName: String) {
// Check that ad is ready and that the placement is not capped
if (mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) {
// Show ad with placement
mRewardedAd.showAd(this, placementName)
}
}
Reward the User
The LevelPlay SDK will fire the onAdRewarded each time the user successfully completes a video.
The onAdRewarded and onAdClosed are asynchronous. Make sure to set up your listener to grant rewards even in cases where onAdRewarded is fired after the onAdClosed.
@override
public void onAdRewarded(@NonNull LevelPlayReward reward, @NonNull LevelPlayAdInfo adInfo) {
// Implement logic to grant the reward to the user
String name = reward.getName();
int amount = reward.getAmount();
}
override fun onAdRewarded(reward: LevelPlayReward, adInfo: LevelPlayAdInfo) {
// Implement logic to grant the reward to the user
val name: String = reward.name
val amount: Int = reward.amount
}
Full Implementation Example of Rewarded Ads
public class RewardedAdActivity extends Activity implements LevelPlayRewardedAdListener {
private LevelPlayRewardedAd mRewardedAd;
void createRewardedAd() {
mRewardedAd = new LevelPlayRewardedAd("adUnitId");
mRewardedAd.setListener(this);
}
void loadRewardedAd() {
// Load or reload the ad
mRewardedAd.loadAd();
}
void showRewardedAd() {
if(mRewardedAd.isAdReady()) {
mRewardedAd.showAd(this);
}
}
void showRewardedAd(@NonNull String placementName) {
// Check that ad is ready and that the placement is not capped
if(mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) {
mRewardedAd.showAd(this, placementName);
}
}
// LevelPlayRewardedAdListener methods
@Override
public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) {}
@Override
public void onAdLoadFailed(@NonNull LevelPlayAdError error) {}
@Override
public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) {}
@Override
public void onAdClosed(@NonNull LevelPlayAdInfo adInfo) {}
@Override
public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) {}
@Override
public void onAdDisplayFailed(@NonNull LevelPlayAdError error, @NonNull LevelPlayAdInfo adInfo) {}
@Override
public void onAdInfoChanged(@NonNull LevelPlayAdInfo adInfo) {}
@Override
public void onAdRewarded(@NonNull LevelPlayReward reward, @NonNull LevelPlayAdInfo adInfo) {}
}
class RewardedAdActivity : Activity(), LevelPlayRewardedAdListener {
private lateinit var mRewardedAd: LevelPlayRewardedAd
fun createRewardedAd() {
mRewardedAd = LevelPlayRewardedAd("adUnitId")
mRewardedAd.setListener(this)
}
fun loadRewardedAd() {
mRewardedAd.loadAd()
}
fun showRewardedAd() {
if (mRewardedAd.isAdReady()) {
mRewardedAd.showAd(this)
}
}
fun showRewardedAd(placementName: String) {
// Check that ad is ready and that the placement is not capped
if (mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) {
mRewardedAd.showAd(this, placementName)
}
}
// LevelPlayRewardedAdListener methods
override fun onAdLoaded(adInfo: LevelPlayAdInfo) {}
override fun onAdLoadFailed(error: LevelPlayAdError) {}
override fun onAdInfoChanged(adInfo: LevelPlayAdInfo) {}
override fun onAdDisplayed(adInfo: LevelPlayAdInfo) {}
override fun onAdDisplayFailed(error: LevelPlayAdError, adInfo: LevelPlayAdInfo) {}
override fun onAdClicked(adInfo: LevelPlayAdInfo) {}
override fun onAdClosed(adInfo: LevelPlayAdInfo) {}
override fun onAdRewarded(reward: LevelPlayReward, adInfo: LevelPlayAdInfo) {}
}
LevelPlay Mediation Demo App
The Integration Demo application demonstrates how to integrate Rewarded Ad Unit APIs in your app.
Download Android Demo Application
Done!
You are now all set up to serve Rewarded ads in your application. Verify your integration with our Integration Test Suite.
Follow our integration guides to integrate additional Rewarded Ad networks or configure additional ad formats: