Rewarded Ads
This guide shows how to display Rewarded Ads in your application.
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.
Before you start, make sure you have correctly integrated and initialized the HyprMX SDK. To integrate and initialize HyprMX, see our Setup Guide.
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.
1. To show an advertisement, use the
getPlacement
API to retrieve a placement from HyprMX, then set a placementListener
.Java
Kotlin
rewardedPlacement = HyprMX.INSTANCE.getPlacement("YOUR_REWARDED_PLACEMENT_NAME");
rewardedPlacement.setPlacementListener(this);
rewardedPlacement = HyprMX.getPlacement("YOUR_REWARDED_PLACEMENT_NAME")
rewardedPlacement.setPlacementListener(this@MainActivity)
2. To check for availability, run the following:
Java
Kotlin
rewardedPlacement.loadAd();
rewardedPlacement.loadAd()
loadAd() will call back to your
placementListener
with:onAdAvailable
when an ad is available.onAdNotAvailable
when there is no inventory.
3. To receive ad load and display status, implement the
RewardedPlacementListener
:Java
Kotlin
/**
* Called when an ad is shown for the given placement. Your application should pause here.
*/
@Override
public void onAdStarted(Placement placement) {}
/**
* Called when an ad is available for the given placement.
*/
@Override
public void onAdAvailable(Placement placement) {}
/**
* Called when an ad is closed. Your application should resume here.
*/
@Override
public void onAdClosed(Placement placement, boolean finished) {}
/**
* Called when there was an error displaying the ad.
*/
@Override
public void onAdDisplayError(Placement placement, HyprMXErrors hyprMXError) {}
/**
* Called when no ad is available for the given placement.
*/
@Override
public void onAdNotAvailable(Placement placement) {}
/**
* Called when the user should be rewarded for the given rewarded placement.
*/
@Override
public void onAdRewarded(Placement placement, String rewardName, Int rewardValue) {}
/**
* The loaded ad has expired. Please load ad again on this placement when you expect to show
*/
@Override
public void onAdExpired(Placement placement) {}
/**
* Called when an ad is shown for the given placement. Your application should pause here.
*/
override fun onAdStarted(placement: Placement) {}
/**
* Called when an ad is available for the given placement.
*/
override fun onAdAvailable(placement: Placement) {}
/**
* Called when an ad is closed. Your application should resume here.
*/
override fun onAdClosed(placement: Placement, finished: Boolean) {}
/**
* Called when there was an error displaying the ad.
*/
override fun onAdDisplayError(placement: Placement, hyprMXError: HyprMXErrors) {}
/**
* Called when no ad is available for the given placement.
*/
override fun onAdNotAvailable(placement: Placement) {}
/**
* Called when the user should be rewarded for the given rewarded placement.
*/
override fun onAdRewarded(placement: Placement, rewardName: String, rewardValue: Int) {}
/**
* The loaded ad has expired. Please load ad again on this placement when you expect to show
*/
override fun onAdExpired(placement:Placement) {}
1. Before calling
showAd
on a placement you should confirm the ad state is still valid by running the following.Java
Kotlin
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
.2. When you are ready to display an ad, call
showAd
to begin the presentation of an ad.Java
Kotlin
if (rewardedPlacement.isAdAvailable()) {
rewardedPlacement.showAd();
}
if (rewardedPlacement.isAdAvailable()) {
rewardedPlacement.showAd()
}
The placement will call back to your
placementListener
to provide you state on the ad display:onAdStarted
is called immediately before attempting to present the ad to the UI.onAdClosed
is called when the ad is closed.onAdDisplayError
is called when an error occurs presenting the ad, and will be followed byonAdClosed
onAdRewarded
is called when a user successfully completes a rewarded advertisement, and will provide you with the reward name and value.onAdExpired
called when the loaded advertisement is no longer available to show.
If you'd like, we can send server-to-server calls when ads are completed. Contact your account manager at HyprMX for more details.