Interstitial Ads

Initialize HyprMX

To integrate and Initialize HyprMX, see our Setup Guide.

Loading Interstitial Advertisements

Placements are objects that allow you to show rewarded and interstitial advertisements. To show an advertisement, use the getPlacement api to retrieve a placement from HyprMX, then set a placementListener.
Please reach out to your account manager to configure your interstitial placements. In return, they will provide the names of the new placements.
Java
Kotlin
1
interstitialPlacement = HyprMX.INSTANCE.getPlacement("YOUR_INTERSTITIAL_PLACEMENT_NAME");
2
interstitialPlacement.setPlacementListener(this);
Copied!
1
interstitialPlacement = HyprMX.getPlacement("YOUR_INTERSTITIAL_PLACEMENT_NAME")
2
interstitialPlacement.setPlacementListener(this@MainActivity)
Copied!
To check for availability, run the following:
Java
Kotlin
1
interstitialPlacement.loadAd();
Copied!
1
interstitialPlacement.loadAd()
Copied!
loadAd() will call back to your placementListener with:
    onAdAvailable when an ad is available.
    onAdNotAvailable when there is no inventory.
To receive ad load and display status, implement the PlacementListener:
Java
Kotlin
1
/**
2
* Called when an ad is shown for the given placement. Your application should pause here.
3
*/
4
@Override
5
public void onAdStarted(Placement placement) {}
6
7
/**
8
* Called when an ad is available for the given placement.
9
*/
10
@Override
11
public void onAdAvailable(Placement placement) {}
12
13
/**
14
* Called when an ad is closed. Your application should resume here.
15
*/
16
@Override
17
public void onAdClosed(Placement placement, boolean finished) {}
18
19
/**
20
* Called when there was an error displaying the ad.
21
*/
22
@Override
23
public void onAdDisplayError(Placement placement, HyprMXErrors hyprMXError) {}
24
25
/**
26
* Called when no ad is available for the given placement.
27
*/
28
@Override
29
public void onAdNotAvailable(Placement placement) {}
30
31
/**
32
* The loaded ad has expired. Please load ad again on this placement when you expect to show
33
*/
34
@Override
35
public void onAdExpired(Placement placement) {}
36
Copied!
1
/**
2
* Called when an ad is shown for the given placement. Your application should pause here.
3
*/
4
override fun onAdStarted(placement: Placement) {}
5
6
/**
7
* Called when an ad is available for the given placement.
8
*/
9
override fun onAdAvailable(placement: Placement) {}
10
11
/**
12
* Called when an ad is closed. Your application should resume here.
13
*/
14
override fun onAdClosed(placement: Placement, finished: Boolean) {}
15
16
/**
17
* Called when there was an error displaying the ad.
18
*/
19
override fun onAdDisplayError(placement: Placement, hyprMXError: HyprMXErrors) {}
20
21
/**
22
* Called when no ad is available for the given placement.
23
*/
24
override fun onAdNotAvailable(placement: Placement) {}
25
26
/**
27
* Called when the user should be rewarded for the given rewarded placement.
28
*/
29
override fun onAdRewarded(placement: Placement, rewardName: String, rewardValue: Int) {}
30
31
/**
32
* The loaded ad has expired. Please load ad again on this placement when you expect to show
33
*/
34
override fun onAdExpired(placement:Placement) {}
Copied!

Displaying Interstitial Advertisements

Before calling showAd on a placement you should confirm the ad state is still valid:
Java
Kotlin
1
interstitialPlacement.isAdAvailable();
Copied!
1
interstitialPlacement.isAdAvailable()
Copied!
When an ad is displaying, it is important to disable all in-game music and sounds so they do not interfere with the advertisements. 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 it will begin the presentation of an ad.
Java
Kotlin
1
if (interstitialPlacement.isAdAvailable()) {
2
interstitialPlacement.showAd();
3
}
Copied!
1
if (interstitialPlacement.isAdAvailable()) {
2
interstitialPlacement.showAd()
3
}
Copied!
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 by onAdClosed
    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.
Last modified 23d ago