Rewarded

Last Updated on: 19 Sep, 2023

Create Rewarded Ad

INFO

  • If you miss to Initialize the SDK, this method will fail to return a response.
  • Ensure that everything is executed on the main thread.

After your adunitId is generated, you can find it on the Meson UI. Add adunitId into the MesonInterstitial object and pass the ActivityContext.

Kotlin

val rewardedAd = MesonInterstitial(this, "AD_UNIT_ID")

Java

MesonInterstitial rewardedAd = new MesonInterstitial(this, "AD_UNIT_ID");

Register for Callbacks

Track the ad lifecycle for interstitial ads. All the available events for interstitial ads are listed below. To retrieve the rewards, use onRewardsUnlocked callback.

Kotlin

rewardedAd.setAdListener(object: MesonInterstitialAdListener() { 
    override fun onAdImpression(ad: MesonInterstitial, mesonAdData: MesonAdData?) { 
    }  

    override fun onAdDisplayed(ad: MesonInterstitial) { 
    }  

    override fun onAdDisplayFailed(ad: MesonInterstitial) { 
    }  

    override fun onAdDismissed(ad: MesonInterstitial) { 
    }  

    override fun onUserLeftApplication(ad: MesonInterstitial) { 
    }  

    override fun onAdLoadSucceeded(ad: MesonInterstitial) { 
    }  

    override fun onAdLoadFailed(ad: MesonInterstitial, status: MesonAdRequestStatus) { 
    }  

    override fun onAdClicked(ad: MesonInterstitial, params: HashMap<String, Any>) { 
    }  

    override fun onRewardsUnlocked(ad: MesonInterstitial, rewards: Map<Any, Any>?) { 
    } 
})

Java

rewardedAd.setAdListener(new MesonInterstitialAdListener() { 
    @Override 
    public void onUserLeftApplication(MesonInterstitial mesonInterstitial) { 
        super.onUserLeftApplication(mesonInterstitial); 
    }  

    @Override 
    public void onAdImpression(MesonInterstitial mesonInterstitial, @Nullable MesonAdData mesonAdData) { 
        super.onAdImpression(mesonInterstitial, mesonAdData); 
    }  

    @Override 
    public void onAdClicked(MesonInterstitial mesonInterstitial, @NonNull HashMap<String, Object> hashMap) { 
        super.onAdClicked(mesonInterstitial, hashMap); 
    }  

    @Override 
    public void onAdLoadFailed(MesonInterstitial mesonInterstitial, @NonNull MesonAdRequestStatus mesonAdRequestStatus) { 
        super.onAdLoadFailed(mesonInterstitial, mesonAdRequestStatus); 
    }  

    @Override 
    public void onAdLoadSucceeded(MesonInterstitial mesonInterstitial) { 
        super.onAdLoadSucceeded(mesonInterstitial); 
    }  

    @Override 
    public void onRewardsUnlocked(@NonNull MesonInterstitial mesonInterstitial, @Nullable Map<Object, ?> map) { 
        super.onRewardsUnlocked(mesonInterstitial, map); 
    }  

    @Override 
    public void onAdDisplayFailed(@NonNull MesonInterstitial mesonInterstitial) { 
        super.onAdDisplayFailed(mesonInterstitial); 
    }  

    @Override 
    public void onAdDismissed(@NonNull MesonInterstitial mesonInterstitial) { 
        super.onAdDismissed(mesonInterstitial); 
    }  

    @Override 
    public void onAdDisplayed(@NonNull MesonInterstitial mesonInterstitial) { 
        super.onAdDisplayed(mesonInterstitial); 
    } 
});

Load Ad

The publisher can request a rewarded ad by invoking this method. This will request an ad from all demand sources, select a winner, and make it available on the SDK.

Kotlin

//use load() to make your interstitial ad request
rewardedAd.load()

Java

//use load() to make your interstitial ad request
rewardedAd.load();

Show Ad

The ad is available when load is called. It is shown to the user when show method is called. It is recommended to call this method in the onAdLoadSucceeded callback method or check isAdReady method to return true and then call show method.

Kotlin

//Use show() to show the ad, the ad will have to be ready before calling show
rewardedAd.show()

Java

//Use show() to show the ad, the ad will have to be ready before calling show
rewardedAd.show();

Destroy Rewarded Ad

Use this method when the rewarded ad is no longer needed. We recommend using this onDestroy of the Activity.

Kotlin

rewardedAd.destroy()

Java

rewardedAd.destroy();