Migrate to Version 6.4+

Please follow the below guide to migrate from the HyprMX SDK 6.x to 6.4+.

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 Gradle to manage your dependencies, you just need to bump the SDK dependency version number. Check out our SDK integration section for more info.

To migrate the HyprMX SDK, update the HyprMX SDK version number to 6.4.1 in your app's build.gradle file dependencies block:

dependencies {
    implementation 'com.hyprmx.android:HyprMX-SDK:6.4.1'
}

Fixing Your Broken Build

See below for migrations related to HyprMX SDK 6.4+.

Migrating HyprMX.initialize

The new SDK initializer parameters only require distributorId and vary slightly by result method. Following is a sample initializer for 6.4+ SDK:

HyprMX.INSTANCE.initialize(this, DISTRIBUTOR_ID, initializationListener);

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);

Migrating the ageRestrictedUser parameter

HyprMX.INSTANCE.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

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 API.

To migrate existing code:

  1. Remove the Placement.setPlacementListener(PlacementListener)

  2. 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 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 PlacementListener {
    void onAdStarted(Placement placement);
    void onAdClosed(Placement placement, boolean finished);
    void onAdDisplayError(Placement placement, HyprMXErrors errors);
    void onAdAvailable(Placement placement);
    void onAdNotAvailable(Placement placement);
    void onAdExpired(Placement placement);
}
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:

  1. Remove the Placement.setPlacementListener(PlacementListener)

  2. 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) {}
});
  1. 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)
}
  1. 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
  }
});

Migrating Banner Placement.loadAd

The new API uses both async and synchronous methods to load a banner ad. To migrate existing code:

  1. Remove the callback methods onAdLoaded and loadAdFailure.

  2. 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:

  1. Remove the callback methods onAdLoaded and onAdFailedToLoad from your HyprMXBannerListener listener implementation.

  2. 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
   }
  }
});

Migration complete.

Last updated