This guide applies to partners upgrading to version 6.4+ from pre-6.4 versions. No migration is needed if you're upgrading from 6.4+.
HyprMX SDK 6.4+ contains a revamp to our public API, streamlining our SDK's initialization and providing more focused callbacks and listeners. Additionally, we now provide modernized asynchronous APIs that you can opt into.
SDK migration
If you're using to manage your dependencies, you just need to bump the SDK dependency version number. Check out our section for more info.
To migrate the HyprMX SDK, update the HyprMX SDK version number to 6.4.2 in your app's build.gradle file dependencies block:
HyprMX.INSTANCE.initialize(this, DISTRIBUTOR_ID, result -> {
// do something
});
HyprMX.initialize(this@MainActivity, DISTRIBUTOR_ID) { result ->
// do something
}
val result = HyprMX.initialize(this@MainActivity, DISTRIBUTOR_ID)
Other parameters have new setters. As a result, you will need to migrate the following parameters:
consentStatus
ageRestrictedUser
userID
Follow the steps below to migrate the parameters.
Migrating the consentStatus parameter
HyprMX.INSTANCE.setConsentStatus(ConsentStatus.CONSENT_GIVEN);
// or
HyprMX.INSTANCE.setConsentStatus(ConsentStatus.CONSENT_DECLINED);
HyprMX.setConsentStatus(ConsentStatus.CONSENT_GIVEN)
// or
HyprMX.setConsentStatus(ConsentStatus.CONSENT_DECLINED)
Migrating the ageRestrictedUser parameter
HyprMX.INSTANCE.setAgeRestrictedUser(true);
HyprMX.setAgeRestrictedUser(true)
Migrating the userId parameter
Our API no longer accepts user ID. Please remove it from the new method signature.
Migrating HyprMxIf.HyprMXInitializationListener
The initializationListener used by initialize, a few code snippets above, is an instance of HyprMxIf.HyprMXInitializationListener as it was in the HyprMX SDK 6.2 although its implementation changed.
The old initializationComplete and initializationFailed listeners were replaced with onInitialized. The latest will callback with a boolean flag to indicate whether the SDK was successfully initialized or not.
Migrating FullScreen Placement.loadAd
To migrate existing code:
Remove the Placement.setPlacementListener(PlacementListener)
Replace the old Placement.loadAd and migrate the code you had inside PlacementListener.onAdAvailable and PlacementListener.onAdNotAvailable to the new loadAd callback.
placement.loadAd(new HyprMXLoadAdListener() {
@Override
public void onAdLoaded(boolean isAdAvailable) {
if (isAdAvailable) {
// Copy code from your old PlacementListener.onAdAvailable
} else {
// Copy code from your old PlacementListener.onAdNotAvailable
}
}
});
placement.loadAd(isAdAvailable -> {
if(isAdAvailable) {
// Copy code from your old PlacementListener.onAdAvailable
} else {
// Copy code from your old PlacementListener.onAdNotAvailable
}
});
placement.loadAd { isAdAvailable ->
if(isAdAvailable) {
// Copy code from your old PlacementListener.onAdAvailable
} else {
// Copy code from your old PlacementListener.onAdNotAvailable
}
}
val isAdAvailable = placement.loadAd()
if(isAdAvailable) {
// Copy code from your old PlacementListener.onAdAvailable
} else {
// Copy code from your old PlacementListener.onAdNotAvailable
}
Migrating FullScreen Placement.showAd
The new Placement.showAd API requires you to define a listener as an argument, HyprMXShowListener. This listener will provide a set of useful callbacks you might need to manipulate the UI state. In fact, some of the PlacementListener callbacks can now be migrated to the new HyprMXShowListener.
Here is a short comparison between PlacementListener and HyprMXShowListener:
interface HyprMXShowListener {
fun onAdStarted(placement: Placement)
fun onAdClosed(placement: Placement, finished: Boolean)
fun onAdDisplayError(placement: Placement, errors: HyprMXErrors)
fun onAdImpression(placement: Placement)
}
To migrate existing code:
Remove the Placement.setPlacementListener(PlacementListener)
Replace the old Placement.showAd and set the HyprMXShowListener instance as argument
placement.showAd(new HyprMXShowListener() {
@Override
public void onAdStarted(@NonNull Placement placement) {}
@Override
public void onAdClosed(@NonNull Placement placement, boolean b) {}
@Override
public void onAdDisplayError(@NonNull Placement placement, @NonNull HyprMXErrors hyprMXErrors) {}
@Override
public void onAdImpression(@NonNull Placement placement) {}
});
placement.showAd(object : HyprMXShowListener {
override fun onAdClosed(placement: Placement, finished: Boolean) {}
override fun onAdDisplayError(placement: Placement, hyprMXError: HyprMXErrors) {}
override fun onAdImpression(placement: Placement) {}
override fun onAdStarted(placement: Placement) {}
})
If you're working with rewarded placements, use HyprMXRewardedShowListener. This specialized listener includes an extra callback to handle the reward logic:
interface HyprMXRewardedShowListener : HyprMXShowListener {
/**
* The ad was rewarded for the placement and will be called before ad finished is called
* This will only be called for rewarded placements
*
* @param placement The placement that was rewarded
* @param rewardName The name of the reward
* @param rewardValue The value of the reward
*/
fun onAdRewarded(placement: Placement, rewardName: String, rewardValue: Int)
}
Note that onAdExpired also disappeared. If you need a callback to onAdExpired then set HyprMXPlacementExpiryListener and call it on your placement using setPlacementExpiryListener.
placement.setPlacementExpiryListener(new HyprMXPlacementExpiryListener() {
@Override
public void onAdExpired(@NonNull Placement placement) {
// Do something
}
});
placement.setPlacementExpiryListener(placement -> {
// Do something
});
placement.setPlacementExpiryListener(object : HyprMXPlacementExpiryListener {
override fun onAdExpired(placement: Placement) {
// Do something
}
})
Migrating Banner Placement.loadAd
The new API uses both async and synchronous methods to load a banner ad. To migrate existing code:
Remove the callback methods onAdLoaded and loadAdFailure.
Replace the old Placement.loadAd and migrate the code you had inside PlacementListener.onAdAvailable and PlacementListener.onAdNotAvailable to the new loadAd callback.
placement.loadAd(new HyprMXLoadAdListener() {
@Override
public void onAdLoaded(boolean isAdAvailable) {
if (isAdAvailable) {
// Copy code from your old PlacementListener.onAdAvailable
} else {
// Copy code from your old PlacementListener.onAdNotAvailable
}
}
});
Migrating HyprMXBannerView
The new API uses both async and synchronous methods to load a banner ad. To migrate existing code:
Remove the callback methods onAdLoaded and onAdFailedToLoad from your HyprMXBannerListener listener implementation.
Replace the old hyprMXBannerView.loadAd() with either one of the following new methods:
hyprMXBannerView.loadAd(new HyprMXLoadAdListener() {
@Override
public void onAdLoaded(boolean isAdAvailable) {
if (isAdAvailable) {
// Copy code from your old HyprMXBannerListener.onAdLoaded
} else {
// Copy code from your old HyprMXBannerListener.onAdFailedToLoad
}
}
});
hyprMXBannerView.loadAd(isAdAvailable -> {
if (isAdAvailable) {
// Copy code from your old HyprMXBannerListener.onAdLoaded
} else {
// Copy code from your old HyprMXBannerListener.onAdFailedToLoad
}
});
hyprMXBannerView.loadAd { isAdAvailable ->
if (isAdAvailable) {
// Copy code from your old HyprMXBannerListener.onAdLoaded
} else {
// Copy code from your old HyprMXBannerListener.onAdFailedToLoad
}
}
val isAdAvailable = hyprMXBannerView.loadAd()
if (isAdAvailable) {
// Copy code from your old HyprMXBannerListener.onAdLoaded
} else {
// Copy code from your old HyprMXBannerListener.onAdFailedToLoad
}
Migration complete.
The new API doesn't require you to set a PlacementListener to load an ad. In fact, this listener no longer exists. Note: You can read more about it while migrating the Placement.showAd .