This guide shows how to display Rewarded Ads in your application.
What are Rewarded Ads?
Rewarded Ad Units reward a user within the app in exchange for completing the ad. This opt-in ad unit provides a less disruptive user experience along with high engagement from users.
How to Display Rewarded Ads
Integrate & Initialize HyprMX
Before you start, make sure you have correctly integrated and initialized the HyprMX SDK. To integrate and initialize HyprMX, see our Setup Guide.
Loading Rewarded Ads
HyprMX utilizes placements to load and display an ad. Placements are used to represent a point in your application's workflow where you'd like to show an ad. To load an ad to a placement, follow the steps below.
If you don't have your placement information, please reach out to your account manager to configure your rewarded placements. In return, they will provide the names of the new placements.
Use the getPlacement API to retrieve a placement from HyprMX.
rewardedPlacement.loadAd(newHyprMXLoadAdListener() { @OverridepublicvoidonAdLoaded(boolean isAdAvailable) {if(isAdAvailable) {// You can show the ad } }});
rewardedPlacement.loadAd(isAdAvailable -> {if(isAdAvailable) {// You can show the ad }});
rewardedPlacement.loadAd { isAdAvailable ->if(isAdAvailable) {// You can show the ad }}
val isAdAvailable = rewardedPlacement.loadAd()if(isAdAvailable) {// You can show the ad}
loadAd() will call back to your listener with isAdAvailable == true when an ad is available or false when there is no inventory.
To receive notification that the loaded ad has expired, implement the HyprMXPlacementExpiryListener
privateHyprMXPlacementExpiryListener listener =newHyprMXPlacementExpiryListener() { @OverridepublicvoidonAdExpired(@NonNullPlacement placement) {// Do something on expiration }}rewardedPlacement.setPlacementExpiryListener(listener);
rewardedPlacement.setPlacementExpiryListener(placement -> {// Do something on expiration});
val listener =object : HyprMXPlacementExpiryListener {overridefunonAdExpired(placement: Placement) {// Do something on expiration }}rewardedPlacement.setPlacementExpiryListener(listener)
Displaying Rewarded Ads
Before calling showAd on a placement, you should confirm the ad state is still valid by running the following.
rewardedPlacement.isAdAvailable();
rewardedPlacement.isAdAvailable()
When an ad is displaying, it is important to disable all in-game music and sounds so they do not interfere with the ads. You can disable them when your activity transitions to onStop and resume when your activity transitions to onResume.
When you are ready to display an ad, call showAd to begin the presentation of an ad.
if (rewardedPlacement.isAdAvailable()) {rewardedPlacement.showAd(this);}
if (rewardedPlacement.isAdAvailable()) { rewardedPlacement.showAd(this)}
To receive ad reward and display status, implement the HyprMXRewardedShowListener:
/** * Called when an ad is shown for the given placement. Your application should pause here. */@OverridepublicvoidonAdStarted(Placement placement) {}/** * Called when an ad is closed. Your application should resume here. */@OverridepublicvoidonAdClosed(Placement placement,boolean finished) {}/** * Called when there was an error displaying the ad. */@OverridepublicvoidonAdDisplayError(Placement placement,HyprMXErrors hyprMXError) {}/** * Called when the ad was impressed. */@OverridepublicvoidonAdImpression(Placement placement) {}/** * Called when the user should be rewarded for the given rewarded placement. */@OverridepublicvoidonAdRewarded(Placement placement,String rewardName,Int rewardValue) {}
/** * Called when an ad is shown for the given placement. Your application should pause here. */overridefunonAdStarted(placement: Placement) {}/** * Called when an ad is closed. Your application should resume here. */overridefunonAdClosed(placement: Placement, finished: Boolean) {}/** * Called when there was an error displaying the ad. */overridefunonAdDisplayError(placement: Placement, hyprMXError: HyprMXErrors) {}/** * Called when the ad was impressed. */overridefunonAdImpression(placement: Placement) {}/** * Called when the user should be rewarded for the given rewarded placement. */overridefunonAdRewarded(placement: Placement, rewardName: String, rewardValue: Int) {}
If you'd like, we can send server-to-server calls when ads are completed. Contact your account manager at HyprMX for more details.