Android / Amazon Setup Guide
The HyprMX SDK is designed to present rewarded, interstitial, and banner ads in your application. To integrate the SDK, follow the steps below. If you're upgrading an existing SDK, please refer to the Upgrade Guide.
You can integrate the HyprMX SDK through Gradle dependencies. Follow the steps below to set up the SDK.
This guide assumes you already have your Gradle-based project up and running in Android Studio.
1. Open your existing application in Android Studio.
2. Add the HyprMX SDK to your app's
build.gradle
file dependencies block:dependencies {
implementation 'com.hyprmx.android:HyprMX-SDK:6.2.0'
}
3. Adding Google Play Services Ads Identifier is optional. If the dependency below is included, it is the responsibility of the app developer to ensure compliance with all Google Play policies, including, and not limited to, Families Program.
dependencies {
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
}
4. If you are using Kotlin in your application, add the following to your
build.gradle
inside the android
block:kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = [
"-Xjvm-default=compatibility",
]
}
Follow the steps below to initialize HyprMX.
1. Add the following imports to your activity:
Java
Kotlin
import com.hyprmx.android.sdk.core.HyprMX;
import com.hyprmx.android.sdk.core.HyprMXIf;
import com.hyprmx.android.sdk.core.HyprMXErrors;
import com.hyprmx.android.sdk.core.HyprMXState;
import com.hyprmx.android.sdk.placement.Placement;
import com.hyprmx.android.sdk.placement.PlacementListener;
import com.hyprmx.android.sdk.placement.RewardedPlacementListener;
import com.hyprmx.android.sdk.core.HyprMX
import com.hyprmx.android.sdk.core.HyprMXErrors
import com.hyprmx.android.sdk.core.HyprMXIf
import com.hyprmx.android.sdk.placement.Placement
import com.hyprmx.android.sdk.placement.PlacementListener
import com.hyprmx.android.sdk.placement.RewardedPlacementListener
2. Initialize the HyprMX SDK in your main
Activity
inside the onCreate
method as shown below. As a best practice, initialize HyprMX as soon as possible (i.e. when your application is loading) so we can begin preloading ads. Review the details of initialization parameters (consentStatus, ageRestrictedUser, distributorId, userId, and initializationListener) below to find out what initializer best suits your app's use case.Use if your app's target audience does not include children and consent API is not applicable:
Java
Kotlin
String distributorID = "Your Distributor ID";
String userID = "Your User's ID";
HyprMXIf.HyprMXInitializationListener initializationListener;
// Use this initializer if your app's target audience does not include children. ageRestrictedUser defaults to false. Consent defaults to UNKNOWN.
HyprMX.INSTANCE.initialize(this, distributorID, userID, initializationListener);
val distributorID = "Your Distributor ID"
val userID = "Your User's ID"
val initializationListener: HyprMXIf.HyprMXInitializationListener = this
// Use this initializer if your app's target audience does not include children. ageRestrictedUser defaults to false. Consent defaults to UNKNOWN.
HyprMX.initialize(this, distributorID, userID, initializationListener)
Use if your app's target audience does not include children:
Java
Kotlin
String distributorID = "Your Distributor ID";
String userID = "Your User's ID";
ConsentStatus consentStatus = ConsentStatus.CONSENT_STATUS_UNKNOWN; // If you don't know consent status for the user, set this to CONSENT_STATUS_UNKNOWN
HyprMXIf.HyprMXInitializationListener initializationListener;
// Use this initializer if your app's target audience does not include children. ageRestrictedUser defaults to false.
HyprMX.INSTANCE.initialize(this, distributorID, userID, consentStatus, initializationListener);
val distributorID = "Your Distributor ID"
val userID = "Your User's ID"
val consentStatus = ConsentStatus.CONSENT_STATUS_UNKNOWN // If you don't have consent status for the user, set this to CONSENT_STATUS_UNKNOWN
val initializationListener: HyprMXIf.HyprMXInitializationListener = this
// Use this initializer if your app's target audience does not include children. ageRestrictedUser defaults to false.
HyprMX.initialize(this, distributorID, userID, consentStatus, initializationListener)
Use if your app's target audience includes children:
Java
Kotlin
String distributorID = "Your Distributor ID";
String userID = "Your User's ID";
ConsentStatus consentStatus = ConsentStatus.CONSENT_STATUS_UNKNOWN; // If you don't have consent status for the user, set this to CONSENT_STATUS_UNKNOWN
HyprMXIf.HyprMXInitializationListener initializationListener;
boolean ageRestrictedUser = true; // Set this to true if the user is under 16
// Use this initializer if your app's target audience includes children.
HyprMX.INSTANCE.initialize(this, distributorID, userID, consentStatus, ageRestrictedUser, initializationListener);
val distributorID = "Your Distributor ID"
val userID = "Your User's ID"
val consentStatus = ConsentStatus.CONSENT_STATUS_UNKNOWN // If you don't have consent status for the user, set this to CONSENT_STATUS_UNKNOWN
val initializationListener: HyprMXIf.HyprMXInitializationListener = this
val ageRestrictedUser = true // Set this to true if the user is under 16
// Use this initializer if your app's target audience includes children.
HyprMX.initialize(this, distributorID, userID, consentStatus, ageRestrictedUser, initializationListener)
The initializer includes a consentStatus parameter for jurisdictions that require passing consent that takes a
ConsentStatus
value depending on the user consent collected by your app:CONSENT_STATUS_UNKNOWN
CONSENT_GIVEN
CONSENT_DECLINED
HyprMX also provides a separate method for setting Consent. Use this when a user's consent status changes:
Java
Kotlin
HyprMX.INSTANCE.setConsentStatus(consentStatus);
HyprMX.setConsentStatus(ConsentStatus.CONSENT_STATUS_UNKNOWN)
HyprMX’s
ageRestrictedUser
flag assists publishers with child-directed treatment of users to support compliance with applicable regional laws and regulations such as COPPA, GDPR and Google Play Store policies.The initializer includes an optional
ageRestrictedUser
parameter. If the user requires child-directed treatment under applicable laws and policies, set this parameter to true.Setting the
ageRestrictedUser
parameter is recommended for all users within applications that participate in Google Play's Families Program, are listed in Google Play’s Family section, or include children as one of the target audiences to prevent access to the AAID for end-users flagged as children.If your app is primarily directed at children, you must indicate to your HyprMX Account Manager so the app can be designated as a child-directed app in the backend. Additionally, you may use the
ageRestrictedUser
flag to prevent access to the AAID for end-users flagged as children.If your app is directed at a mixed audience, including children, you must use the
ageRestrictedUser
flag to appropriately flag any user who is considered a child under applicable jurisdiction as an age-restricted user to prevent access to the AAID for end-users flagged as children.It is the responsibility of the app developer to ensure compliance with Google Play's Families Program, including, and not limited to, Google Play Families Policies.
The value for
distributorID
is assigned to your app by HyprMX. If you have not received this ID and your placements information, please reach out to your HyprMX account manager.The userID is a unique identifier supplied by your application and must be static for each user across sessions. Your userID should not contain any personally identifiable information such as an email address, screen name, Android Device ID (AID), or Google Advertising ID/Android Advertising ID (GAID/AAID). If you don’t already have a static user identifier, you can use the code below to generate one.
Java
Kotlin
private String getUserId() {
SharedPreferences sharedPreferences = getSharedPreferences("hyprmx_prefs", Context.MODE_PRIVATE);
String userID = sharedPreferences.getString("hyprUserId", null);
if (userID == null) {
userID = UUID.randomUUID().toString();
sharedPreferences.edit().putString("hyprUserId", userID).apply();
}
return userID;
}
private fun getUserId(): String {
val sharedPreferences = getSharedPreferences("hyprmx_prefs", Context.MODE_PRIVATE)
var userID = sharedPreferences.getString("hyprUserId", null)
if (userID == null) {
userID = UUID.randomUUID().toString()
sharedPreferences.edit().putString("hyprUserId", userID).apply()
}
return userID
}
initializationListener is the listener for Initialization Status of the SDK. It will callback to initializationComplete or initializationFailed as below:
Java
Kotlin
HyprMXIf.HyprMXInitializationListener initializationListener = new HyprMXIf.HyprMXInitializationListener() {
@Override
public void initializationComplete() {}
@Override
public void initializationFailed() {}
};
val initializationListener = object : HyprMXIf.HyprMXInitializationListener {
override fun initializationComplete() {}
override fun initializationFailed() {}
}
After receiving the
initializationDidComplete
callback, you are now ready to load and display ads in your application. See our Rewarded Ads, Interstitial Ads, and Banner Ads guides to add these ad types to your app.Last modified 9d ago