Rewarded Video Ads

Set up a Rewarded Video Ad

  1. From the left navigation select Inventory Inventory Settings.
  2. Search for the app or website you would like to create a placement for and click + Add a placement.
  3. Click Select Ad Unit and select Rewarded Video.
  4. Click Add a placement to start setting up your rewarded video settings. After you create the rewarded video placement, you can see the placement ID.

Important

InMobi SDK provides you the callback in any case, so you could choose not to fill in anything and handle the rewards completely at your end.


Add Rewarded Video Ad to your App

Creating a Rewarded Video Ad

To create a rewarded video ad, create an instance of an InMobiInterstitial:

Java

InMobiInterstitial interstitialAd = new InMobiInterstitial(InterstitialAdsActivity.this, 1471550843414L, 
mInterstitialAdEventListener);

Kotlin

val interstitialAd = InMobiInterstitial(this@InterstitialAdsActivity, 1471550843414L, 
mInterstitialAdEventListener)

Here, mInterstitialAdEventListener is an implementation of the InterstitialAdEventListener abstract class. It is mandatory to supply an implementation of this interface to create an interstitial ad.

Note

  • The InMobiInterstitial class is not thread-safe. An interstitial instance must be created on the UI thread.
  • Similarly, all methods on this instance must be called on the UI thread. Not doing so will lead to unpredictable behavior and may affect your ability to monetize with InMobi.
  • Creating an InMobiInterstitial object without SDK Initialization will throw an exception.

The InterstitialAdEventListener abstract class allows you to listen to key lifecycle events for an interstitial ad. You should listen to these events to ensure that your application correctly handles the various lifecycle transitions.

Java

/** 
 * Listener for receiving notifications during the lifecycle of an interstitial. 
 */
public abstract class InterstitialAdEventListener {
    /** 
     * Called to indicate that an ad was loaded and it can now be shown. This will always be called 
     * after the {@link #onAdFetchSuccessful(InMobiInterstitial, AdMetaInfo)} callback. 
     * 
     * @param ad Represents the {@link InMobiInterstitial} ad which was loaded 
     * @param info Represents the ad meta information 
     */
    public void onAdLoadSucceeded(@NonNull InMobiInterstitial ad, @NonNull AdMetaInfo info) {}
    /** 
     * Callback to signal that a request to fetch an ad (by calling 
     * {@link InMobiInterstitial#load()} failed. The status code indicating the reason for failure 
     * is available as a parameter. You should call {@link InMobiInterstitial#load()} again to 
     * request a fresh ad. 
     * 
     * @param ad Represents the {@link InMobiInterstitial} ad which failed to load 
     * @param status Represents the {@link InMobiAdRequestStatus} status containing error reason 
     */
    public void onAdLoadFailed(@NonNull InMobiInterstitial ad, InMobiAdRequestStatus status) {}
    /** 
     * Called to indicate that an ad is available in response to a request for an ad (by calling 
     * {@link InMobiInterstitial#load()}.Note: This does not 
     * indicate that the ad can be shown yet. Your code should show an ad after the 
     * {@link #onAdLoadSucceeded(InMobiInterstitial)} method is called. Alternately, if you do not 
     * want to handle this event, you must test if the ad is ready to be shown by checking the 
     * result of calling the {@link InMobiInterstitial#isReady()} method. 
     * 
     * @param ad Represents the {@link InMobiInterstitial} ad for which ad content was received 
     * @param info Represents the ad meta information 
     */
    public void onAdFetchSuccessful(@NonNull InMobiInterstitial ad, @NonNull AdMetaInfo info) {}
    /** 
     * Called to indicate that an ad interaction was observed. 
     * 
     * @param ad Represents the {@link InMobiInterstitial} ad on which user clicked 
     * @param params Represents the click parameters 
     */
    public void onAdClicked(@NonNull InMobiInterstitial ad, Map < Object, Object > params) {}
    /** 
     * Called to indicate that the ad will be launching a fullscreen overlay. 
     * 
     * @param ad Represents the {@link InMobiInterstitial} ad which will display 
     */
    public void onAdWillDisplay(@NonNull InMobiInterstitial ad) {}
    /** 
     * Called to indicate that the fullscreen overlay is now the topmost screen. 
     * 
     * @param ad Represents the {@link InMobiInterstitial} ad which is displayed 
     * @param info Represents the ad meta information 
     */
    public void onAdDisplayed(@NonNull InMobiInterstitial ad, @NonNull AdMetaInfo info) {}
    /** 
     * Called to indicate that a request to show an ad (by calling {@link InMobiInterstitial#show()} 
     * failed. You should call {@link InMobiInterstitial#load()} to request for a fresh ad. 
     * 
     * @param ad Represents the {@link InMobiInterstitial} ad which failed to show 
     */
    public void onAdDisplayFailed(@NonNull InMobiInterstitial ad) {}
    /** 
     * Called to indicate that the fullscreen overlay opened by the ad was closed. 
     * 
     * @param ad Represents the {@link InMobiInterstitial} ad which was dismissed 
     */
    public void onAdDismissed(@NonNull InMobiInterstitial ad) {}
    /** 
     * Called to indicate that the user may leave the application on account of interacting with the ad. 
     * 
     * @param ad Represents the {@link InMobiInterstitial} ad 
     */
    public void onUserLeftApplication(@NonNull InMobiInterstitial ad) {}
    /** 
     * Called to indicate that rewards have been unlocked. 
     * 
     * @param ad Represents the {@link InMobiInterstitial} ad for which rewards was unlocked 
     * @param rewards Represents the rewards unlocked 
     */
    public void onRewardsUnlocked(@NonNull InMobiInterstitial ad, Map < Object, Object > rewards) {}
}

Kotlin

/** 
* Listener for receiving notifications during the lifecycle of an interstitial. 
*/ 
abstract class InterstitialAdEventListener : AdEventListener<inmobiinterstitial>() { 
   /** 
    * Called to notify that an ad preload has failed. 
    * 
    ***Note** This notification is given only when you use `preload()` in 
    * [InMobiInterstitial.preloadManager] 
    * 
    * @param ad     Represents the [InMobiInterstitial] ad which was preloaded 
    * @param status Represents the [InMobiAdRequestStatus] status containing error reason 
    */ 
   open fun onAdFetchFailed(ad: InMobiInterstitial, status: InMobiAdRequestStatus) {} 
   /** 
    * Called to indicate that the ad will be launching a fullscreen overlay. 
    * 
    * @param ad Represents the [InMobiInterstitial] ad which will display 
    */ 
   open fun onAdWillDisplay(ad: InMobiInterstitial) {} 
   /** 
    * Called to indicate that the fullscreen overlay is now the topmost screen. 
    * 
    * @param ad   Represents the [InMobiInterstitial] ad which is displayed 
    * @param info Represents the meta info for the ad displayed 
    */ 
   open fun onAdDisplayed(ad: InMobiInterstitial, info: AdMetaInfo) {} 
   /** 
    * Called to indicate that a request to show an ad (by calling [InMobiInterstitial.show] 
    * failed. You should call [InMobiInterstitial.load] to request for a fresh ad. 
    * 
    * @param ad Represents the [InMobiInterstitial] ad which failed to show 
    */ 
   open fun onAdDisplayFailed(ad: InMobiInterstitial) {} 
   /** 
    * Called to indicate that the fullscreen overlay opened by the ad was closed. 
    * 
    * @param ad Represents the [InMobiInterstitial] ad which was dismissed 
    */ 
   open fun onAdDismissed(ad: InMobiInterstitial) {} 
   /** 
    * Called to indicate that the user may leave the application on account of interacting with the ad. 
    * 
    * @param ad Represents the [InMobiInterstitial] ad 
    */ 
   open fun onUserLeftApplication(ad: InMobiInterstitial) {} 
   /** 
    * Called to indicate that rewards have been unlocked. 
    * 
    * @param ad      Represents the [InMobiInterstitial] ad for which rewards was unlocked 
    * @param rewards Represents the rewards unlocked 
    */ 
   open fun onRewardsUnlocked(ad: InMobiInterstitial, rewards: Map<any, any="">) {} 
}


Loading a Rewarded Ad

To request for a interstitial ad, call the load() method on the InMobiInterstitial instance:

Java

interstitialAd.load();

Kotlin

interstitialAd.load()

You will be notified of the result of this method via the InterstitialAdEventListener event interface. If the ad request was successful, the onAdFetchSuccessful(InMobiInterstitial, AdMetaInfo) event will be generated. This will be followed by either the onAdLoadSucceeded or the onAdLoadFailed event. If the onAdLoadFailed event is generated, the reason is indicated by the InMobiAdRequestStatus object passed in this event. If the onAdLoadSucceeded event is generated, you may now show the ad anytime after this by calling show() on the InMobiInterstitial instance.

Note

Calling load() on the same interstitial ad after the onAdLoadSucceeded event is generated by the SDK is not guaranteed to request a fresh ad from the network. A fresh ad will only be fetched if either the previous ad was discarded by the SDK, or if the ad expired or the user cleared application data and caches.


Showing a Rewarded Video Ad

To show a rewarded video ad, just call show() on the InMobiInterstitial instance anytime after the onAdLoadSucceeded event has been generated by the SDK. The code fragment below illustrates this:

Java

InMobiInterstitial interstitialAd;
InterstitialAdEventListener mInterstitialAdEventListener = new InterstitialAdEventListener() {
    // implementation for other events 
    // onAdFetchSuccessful, onAdLoaFailed, etc 
    @Override
    public void onAdLoadSucceeded(@NonNull InMobiInterstitial inMobiInterstitial, @NonNull AdMetaInfo info) {
        Log.d(TAG, "Ad can now be shown!");
        mCanShowAd = true;
    }
};
void init() {
    interstitialAd = new InMobiInterstitial(GameActivity.this, 1471550843414 L, mInterstitialAdEventListener);
}
void prepareGameLevel() {
    interstitialAd.load();
}
void handleGameLevelCompleted() {
    If(mCanShowAd) interstitialAd.show();
}

Kotlin

val interstitialAd: InMobiInterstitial 
val mInterstitialAdEventListener = InterstitialAdEventListener() { 
   // implementation for other events 
   // onAdFetchSuccessful, onAdLoadFailed, etc 
   override fun onAdLoadSucceeded(inMobiInterstitial: InMobiInterstitial, info: AdMetaInfo) { 
       Log.d(TAG, "Ad can now be shown!") 
       mCanShowAd = true 
   } 
} 
fun init() { 
   val interstitialAd = InMobiInterstitial(this@GameActivity, 1471550843414L, mInterstitialAdEventListener) 
} 
fun prepareGameLevel() { 
   interstitialAd.load() 
} 
fun handleGameLevelCompleted() { 
   if(mCanShowAd) interstitialAd.show() 
} 

Your application will be notified of the result of this request via the InterstitialAdEventListener’s callbacks. If the ad can be shown, then the SDK will notify your code by calling on the onAdWillDisplay interface, followed by calling the onAdDisplayed method when the ad is actually presented on the screen. If the ad cannot be displayed, the onAdDisplayFailed event is generated by the SDK to let your application know that the ad could not be displayed. You can request for a fresh ad by calling load() again to handle this event.

When an interstitial ad is dismissed, your application will be notified in the onAdDismissed callback.


Implementing Callback for Rewards

For rewarded video ads, the SDK will generate the onAdRewardActionCompleted event.

Java

InterstitialAdEventListener mInterstitialAdEventListener = new InterstitialAdEventListener() { 
    // implementation for other events  
    // onAdLoadSucceeded, onAdDisplayed, etc  
    @Override 
    public void onRewardsUnlocked(@NonNull InMobiInterstitial inMobiInterstitial, Map < Object, Object > map) { 
        Log.d(TAG, "Ad rewards unlocked!"); 
        for (Object key: map.keySet()) { 
            Object value = map.get(key); 
            Log.v(TAG, "Unlocked " + value + " " + key); 
        } 
    } 
};

Kotlin

val mInterstitialAdEventListener: InterstitialAdEventListener = 
   object : InterstitialAdEventListener() { 
       // implementation for other events 
       // onAdLoadSucceeded, onAdDisplayed, etc 
       override fun onRewardsUnlocked( inMobiInterstitial: InMobiInterstitial, 
           map: Map<any, any=""> 
       ) { 
           Log.d(TAG, "Ad rewards unlocked!") 
           for (key in map.keys) { 
               val value = map[key] 
               Log.v(TAG, "Unlocked $value $key") 
           } 
       } 
   }

You can check the code samples for interstitial ad integrations on GitHub here.

On This Page

Last Updated on: 18 May, 2023