> For the complete documentation index, see [llms.txt](https://documentation.hyprmx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.hyprmx.com/sdk-integration-guides/android-amazon/migrate-to-version-6.4+.md).

# Migrate to Version 6.4+

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

{% hint style="info" %}
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+.
{% endhint %}

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](https://gradle.org/) to manage your dependencies, you just need to bump the SDK dependency version number. Check out our [SDK integration](/sdk-integration-guides/android-amazon.md) section for more info.

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

```gradle
dependencies {
    implementation 'com.hyprmx.android:HyprMX-SDK:6.4.7'
}
```

## Fixing Your Broken Build <a href="#quickstart-initializinghyprmx" id="quickstart-initializinghyprmx"></a>

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:&#x20;

{% tabs %}
{% tab title="Java" %}

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

{% endtab %}

{% tab title="Java (Lambda)" %}

```java
HyprMX.INSTANCE.initialize(this, DISTRIBUTOR_ID, result -> {
  // do something
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
HyprMX.initialize(this@MainActivity, DISTRIBUTOR_ID) { result ->
  // do something
}
```

{% endtab %}

{% tab title="Kotlin (Coroutines)" %}

```kotlin
val result = HyprMX.initialize(this@MainActivity, DISTRIBUTOR_ID)
```

{% endtab %}
{% endtabs %}

Other parameters have new setters. As a result, you will need to migrate the following parameters:&#x20;

* `consentStatus`
* `ageRestrictedUser`
* `userID`

Follow the steps below to migrate the parameters.

#### **Migrating the `consentStatus` parameter**

{% tabs %}
{% tab title="Java" %}

```java
HyprMX.INSTANCE.setConsentStatus(ConsentStatus.CONSENT_GIVEN);

// or
HyprMX.INSTANCE.setConsentStatus(ConsentStatus.CONSENT_DECLINED);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
HyprMX.setConsentStatus(ConsentStatus.CONSENT_GIVEN)

// or
HyprMX.setConsentStatus(ConsentStatus.CONSENT_DECLINED)
```

{% endtab %}
{% endtabs %}

#### **Migrating the `ageRestrictedUser` parameter**

{% tabs %}
{% tab title="Java" %}

```java
HyprMX.INSTANCE.setAgeRestrictedUser(true);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
HyprMX.setAgeRestrictedUser(true)
```

{% endtab %}
{% endtabs %}

#### **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](#migrating-fullscreen-placement.showad).<br>

To migrate existing code:

{% stepper %}
{% step %}
Remove the `Placement.setPlacementListener(PlacementListener)`

{% endstep %}

{% step %}
Replace the old `Placement.loadAd` and migrate the code you had inside `PlacementListener.onAdAvailable` and `PlacementListener.onAdNotAvailable` to the new loadAd callback.

{% tabs %}
{% tab title="Java" %}

```java
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
   }
  }
});
```

{% endtab %}

{% tab title="Java (Lambda)" %}

```java
placement.loadAd(isAdAvailable -> {
    if(isAdAvailable) {
      // Copy code from your old PlacementListener.onAdAvailable
   } else {
      // Copy code from your old PlacementListener.onAdNotAvailable
   }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
placement.loadAd { isAdAvailable ->
   if(isAdAvailable) {
      // Copy code from your old PlacementListener.onAdAvailable
   } else {
      // Copy code from your old PlacementListener.onAdNotAvailable
   }
}
```

{% endtab %}

{% tab title="Kotlin (Coroutines)" %}

```kotlin
val isAdAvailable = placement.loadAd()

if(isAdAvailable) {
   // Copy code from your old PlacementListener.onAdAvailable
} else {
   // Copy code from your old PlacementListener.onAdNotAvailable
}
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

### 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`.&#x20;

Here is a short comparison between PlacementListener and HyprMXShowListener:&#x20;

```java
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);
}
```

```java
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:

{% stepper %}
{% step %}
Remove the `Placement.setPlacementListener(PlacementListener)`

{% endstep %}

{% step %}
Replace the old `Placement.showAd` and set the `HyprMXShowListener` instance as argument

{% tabs %}
{% tab title="Java" %}

<pre class="language-java"><code class="lang-java">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) {}
<strong>});
</strong></code></pre>

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
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) {}
})
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}
If you're working with rewarded placements, use `HyprMXRewardedShowListener`. This specialized listener includes an extra callback to handle the reward logic:

```java
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)
}
```

{% endstep %}

{% step %}
Note that onAdExpired also disappeared. If you need a callback to onAdExpired, then set `HyprMXPlacementExpiryListener` and call it on your placement using `setPlacementExpiryListener`.

{% tabs %}
{% tab title="Java" %}

```java
placement.setPlacementExpiryListener(new HyprMXPlacementExpiryListener() {
  @Override
  public void onAdExpired(@NonNull Placement placement) {
    // Do something
  }
});
```

{% endtab %}

{% tab title="Java (Lambda)" %}

```java
placement.setPlacementExpiryListener(placement -> {
    // Do something
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
placement.setPlacementExpiryListener(object : HyprMXPlacementExpiryListener {
  override fun onAdExpired(placement: Placement) {
    // Do something
  }
})
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

### Migrating Banner Placement.loadAd

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

{% stepper %}
{% step %}
Remove the callback methods onAdLoaded and loadAdFailure.

{% endstep %}

{% step %}
Replace the old `Placement.loadAd` and migrate the code you had inside `PlacementListener.onAdAvailable` and `PlacementListener.onAdNotAvailable` to the new loadAd callback.

{% tabs %}
{% tab title="Java" %}

```java
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
   }
  }
});
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

### Migrating HyprMXBannerView

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

{% stepper %}
{% step %}
Remove the callback methods onAdLoaded and onAdFailedToLoad from your `HyprMXBannerListener` listener implementation.

{% endstep %}

{% step %}
Replace the old `hyprMXBannerView.loadAd()` with either one of the following new methods:

{% tabs %}
{% tab title="Java" %}

```java
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
   }
  }
});
```

{% endtab %}

{% tab title="Java (Lambda)" %}

<pre class="language-java"><code class="lang-java"><strong>hyprMXBannerView.loadAd(isAdAvailable -> {
</strong>    if (isAdAvailable) {
      // Copy code from your old HyprMXBannerListener.onAdLoaded
   } else {
      // Copy code from your old HyprMXBannerListener.onAdFailedToLoad
   }
});
</code></pre>

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
hyprMXBannerView.loadAd { isAdAvailable ->
   if (isAdAvailable) {
      // Copy code from your old HyprMXBannerListener.onAdLoaded
   } else {
      // Copy code from your old HyprMXBannerListener.onAdFailedToLoad
   }
}
```

{% endtab %}

{% tab title="Kotlin (Coroutiness)" %}

```kotlin
val isAdAvailable = hyprMXBannerView.loadAd()

if (isAdAvailable) {
    // Copy code from your old HyprMXBannerListener.onAdLoaded
} else {
    // Copy code from your old HyprMXBannerListener.onAdFailedToLoad
}
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

That's it! You're done with the migration.<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://documentation.hyprmx.com/sdk-integration-guides/android-amazon/migrate-to-version-6.4+.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
