Android
Adiz Android¶
Adiz Android is an advertising module for Android provided by Hive to make it easier to use the ad exposure features offered by AdMob. The types of ads provided by Adiz Android are as follows.
- Interstitial Ads
- Banner Ads
- Native Ads
- Rewarded Ads
- Rewarded Interstitial Ads
- App Open Ads
To install and use Adiz Android, please refer to the guide below in order.
Installation¶
Add the Adiz library entry to the app-level Gradle file (app/build.gradle).
To support Java 8 features, add the following under the android
settings in the module's app-level Gradle file.
android {
// ...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
AndroidManifest.xml file, enter AdMobId
(in the format ca-app-pub-XXXXX~YYYYY).
<manifest>
<application>
<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
</manifest>
When using Proguard, the ProGuard rules for the Adiz module are included. Therefore, there is no need to add ProGuard rules to the project.
To display video ads, you need to enable hardware acceleration. Add the settings for hardware acceleration in the AndroidManifest.xml file. Adding it to the application
tag enables hardware acceleration for the entire application. Adding it to the activity
tag enables hardware acceleration only for the specific Activity
where you want to display ads.
<application android:hardwareAccelerated="true">
<!-- For activities that use ads, hardwareAcceleration should be true. -->
<activity android:hardwareAccelerated="true" />
</application>
Test ad settings¶
Adiz can display test ads in two ways.
- Activate test mode: Only test ads issued by AdMob will be displayed
- Display ads after registering test devices: Display real ads for testing, ensuring that invalid traffic does not occur, and proceed by registering devices that will display test ads
Activate test mode¶
In the development stage, activate the test mode so that clicking on test ads does not charge the advertiser. When the test mode is activated, only test ads will be displayed. In test mode, test ads will be displayed even if the AdMob ad key is not entered in the console. Disable the test mode during commercial distribution.
There are two ways to activate test mode.
- After registering the test device in the Hive console, set it up with demo ads (recommended):
Please refer to the Managing Test Devices section of the console guide. - Use the Adiz class's
setTestMode()
method:
Refer to the example code below.
Note
When not in test mode during the development stage, excessive clicks on ads may be considered invalid traffic, and your AdMob account may be reported, preventing ads from being displayed.
Using Adiz.setTestMode() method¶
import com.hive.adiz.Adiz
import com.hive.adiz.AdizError
import org.json.JSONException
import org.json.JSONObject
// Enable test mode. Comment out the line below for commercial distribution.
Adiz.setTestMode(true)
// Enable logging for Hive Adiz module. Logging should only be used in test mode. Comment out the line below for commercial distribution.
Adiz.setLogEnable(true)
import com.hive.adiz.Adiz;
import com.hive.adiz.AdizError;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
// Enable test mode. Comment out the line below for commercial distribution.
Adiz.setTestMode(true);
// Enable logging for Hive Adiz module. Logging should only be used in test mode. Comment out the line below for commercial distribution.
Adiz.setLogEnable(true);
Test device Ad exposure¶
In the following situations, you need to register a test device to display test ads.
- When testing if the AdMob ad key registered in the console is working properly
- When writing a GDPR message and checking if the GDPR consent popup is functioning correctly
- When running the ad inspector to analyze and debug ad requests
<
There are two ways to display ads on the test device.
-
After registering the test device in the Hive console, set it to Use Ad Unit ID (recommended):
Please refer to the Managing Test Devices section of the console guide. -
Use the Adiz class's
setTestDevice()
method:
Refer to the example code below.
Note
If you conduct a test that exposes actual ads without registering a test device, it will be considered invalid traffic, and your AdMob account may be blocked, preventing further ad exposure. When you register a test device, "Test Mode" or "Test Ad" (native ads) will be displayed during ad exposure. You must deactivate the test device during commercial distribution.
Banner, interstitial ads, or rewarded ads
Using Adiz.setTestDevice() method¶
To register a test device, you first need to check the test device ID. The test device ID (example: 33BE2250B43518CCDA7DE426D04EE231
) can be verified in two ways below.
-
Check the Logcat logs after calling
Adiz.Initialize()
: -
After calling
Adiz.Initialize()
, regardless of the ad type, callinitialize()
→load()
and check the Logcat logs:
After checking the test device ID, add the line Adiz.setTestDevice(DEVICE_ID)
before executing Adiz.initialize
in the existing Adiz initialization code. Enter the copied test device ID in DEVICE_ID
.
import com.hive.Adiz
import com.hive.adiz.AdizError
import org.json.JSONObject
fun initialize() {
Adiz.setTestDevice("33BE2250B43518CCDA7DE426D04EE231")
Adiz.initialize(activity, object : Adiz.SdkInitializationListener {
override fun onComplete(error: AdizError, jsonData: JSONObject?) {
// ... omitted
}
})
}
import com.hive.Adiz;
import com.hive.adiz.AdizError;
import org.json.JSONObject;
public void initialize() {
Adiz.setTestDevice("33BE2250B43518CCDA7DE426D04EE231");
Adiz.initialize(activity, new Adiz.SdkInitializationListener() {
@Override
public void onComplete(@NonNull AdizError error, @Nullable JSONObject jsonData) {
if(error.isSuccess()) {
// ... omitted
}
}
});
}
import com.hive.Adiz;
import com.hive.adiz.AdizError;
import org.json.JSONObject;
public void initialize() {
Adiz.setTestDevice("33BE2250B43518CCDA7DE426D04EE231");
Adiz.initialize(activity, new Adiz.SdkInitializationListener() {
@Override
public void onComplete(@NonNull AdizError error, @Nullable JSONObject jsonData) {
if(error.isSuccess()) {
// ... omitted
}
}
});
}
Ad inspector usage¶
The Ad Inspector is an in-app overlay tool that analyzes the process of requesting and displaying actual ads on a test device in real-time. It informs you of the time taken to load the ad and, if the display fails, provides the reason for the failure. You can also specify a particular ad network to check if the ads are displaying properly, and if there are issues, you can debug at the code level. All of this is done alongside the Ad Inspector UI. It is included in Google Mobile Ads SDK version 20.0.0 and above, and can be used by calling AdizDeveloperTool.openAdInspector
.
To use the ad inspector, ad exposure on the test device must be set.
Adiz AppID configuration¶
Set the Adiz AppID that was registered in the AppCenter console. If not set, the AndroidManifest.xml package name will be used.
Hive Console server settings¶
Set up the Hive console server to use. The default is REAL
. Even if you use the production server, enabling test mode will only display test ads.
- Hive Test Console Server:
ZoneType.TEST
- Hive Sandbox Console Server:
ZoneType.SANDBOX
- Hive Production Console Server:
ZoneType.REAL
GDPR consent popup display (Europe, UK)¶
If the game targets Europe and the UK (EEA & UK), a GDPR (General Data Protection Regulation) consent popup must be displayed. The GDPR consent popup will only be shown if the user's device IP address is from Europe and the UK (EEA & UK). Adiz supports the display of the GDPR consent popup through Google UMP (User Messaging Platform). After creating the GDPR message in the AdMob console, initialize Adiz to display the GDPR popup to users accessing from Europe and the UK.
Warning
If you are targeting regions outside of Europe and the UK, for example, if you are planning to provide services only domestically, you can skip the GDPR consent popup exposure (Europe, UK) step and proceed with initialization using the Adiz.initializeForNonGDPR()
method.
If you use the Adiz.initialize()
method for initialization, you must write a GDPR message in the AdMob console for Adiz initialization to proceed normally.
GDPR message creation¶
1) Access the Google AdMob dashboard and create your GDPR message. Before creating the GDPR message, please refer to the GDPR message creation guide.
When creating a GDPR message, you must add the mediation you wish to use to the list of advertising partners. Here is how to add mediation.
1) Go to the Privacy & Messaging > European Regulations > Settings tab on the Google AdMob dashboard, then click the edit icon for 'Ad Partner Review > Custom Ad Partners. 2) Check all mediation partners certified by Google under GDPR to add them in bulk, or select only the desired mediation partners and click Add.
If you have written a GDPR message, the GDPR consent popup will automatically appear when you initialize Adiz.
Implementation of GDPR consent/withdrawal function¶
The items in the GDPR consent popup must provide users with the ability to modify their consent status at any time. For example, a user may initially not consent to GDPR but later wish to consent again in order to view personalized ads, or conversely, a user may initially consent to GDPR but later wish to withdraw their consent because they no longer want to provide personal information. To address these situations, app developers must implement functionality that allows users to re-consent to each item or withdraw their existing consent. To implement the GDPR consent/withdrawal function, follow these steps.
- Implement a button UI in the app that can reopen the GDPR consent popup.
- When implementing Adiz initialization, call
isPrivacyOptionsRequired()
to display the above button UI to users accessing from Europe and the UK, and do not display it otherwise. If a user accessing from Europe or the UK clicks the button, callshowPrivacyOptionsForm
to reopen the GDPR consent popup. This allows users to modify their consent for GDPR details at any time by pressing a button like "Manage Options" in the app. TheshowPrivacyOptionsForm
below is a method implemented arbitrarily for example purposes, and the developer can change the implementation as desired.
import com.hive.Adiz
import com.hive.adiz.AdizError
import com.hive.AdizConsentManager
import org.json.JSONObject
fun initialize() {
// ...
Adiz.initialize(activity, object : Adiz.SdkInitializationListener {
override fun onComplete(error: AdizError, jsonData: JSONObject?) {
if(error.isSuccess) {
// ... omitted
// Decide whether to display a button in the app to reopen the GDPR consent popup
var isPrivacyOptionsRequired = AdizConsentManager.isPrivacyOptionsRequired()
if(isPrivacyOptionsRequired) {
// Display the button in the app. (When the button is clicked, showPrivacyOptionsForm() is called to display the GDPR consent popup)
showGDPRConsentPopupButton()
} else {
// Do not display the button in the app.
// Other processing desired by the app.
}
}
}
})
}
fun showPrivacyOptionsForm(activity: Activity) {
// GDPR consent options form call
if(AdizConsentManager.isPrivacyOptionsRequired()) {
AdizConsentManager.showPrivacyOptionsForm(activity, object : AdizConsentManager.ConsentListener {
override fun onResult(error: AdizError) {
addLog("AdizConsentManager.showPrivacyOptionsForm() errorCode : ${error.getCode()}, errorMessage : ${error.getMessage()}}\n")
// No need to do any error handling.
}
})
}
}
import com.hive.adiz.Adiz;
import com.hive.adiz.AdizError;
import com.hive.AdizConsentManager;
import org.json.JSONObject;
public void initialize() {
Adiz.initialize(activity, new Adiz.SdkInitializationListener() {
@Override
public void onComplete(@NonNull AdizError error, @Nullable JSONObject jsonData) {
if(error.isSuccess()) {
// ... omitted
// Decide whether to display a button in the app to reopen the GDPR consent popup
boolean isPrivacyOptionsRequired = AdizConsentManager.isPrivacyOptionsRequired();
if(isPrivacyOptionsRequired) {
// Display the button in the app. (When the button is clicked, showPrivacyOptionsForm() is called to display the GDPR consent popup)
showGDPRConsentPopupButton();
} else {
// Do not display the button in the app.
// Other processing as desired by the app.
}
}
}
});
}
public void showPrivacyOptionsForm(Activity activity) {
// Call GDPR consent options form
if(AdizConsentManager.isPrivacyOptionsRequired()) {
AdizConsentManager.showPrivacyOptionsForm(activity, new AdizConsentManager.ConsentListener() {
@Override
public void onResult(@NonNull AdizError error) {
// No need to do any error handling.
}
});
}
}
Setting tags for users under GDPR consent age (TFUA)¶
You can use the Tag For Under the Age of Consent (TFUA) to treat users residing in the European Economic Area (EEA), the UK, and Switzerland as limited data processing subjects when making advertising requests. For apps targeting children, you can set the user as under the age of consent using AdizConsentManager.setUserPrivacySettings
. While there are some differences between European countries, GDPR defines the age requiring parental consent as under 16 years old. The under age of consent setting must be configured before executing Adiz.initialize
.
Warning
Setting both the GDPR underage consent tag setTagForUnderAgeOfConsent
and the COPPA child-directed treatment setting setTagForChildDirectedTreatment
to true
at the same time will result in the COPPA child-directed treatment setting setTagForChildDirectedTreatment
taking precedence. Therefore, do not set both to true
and use them simultaneously.
Note
When using Hive SDK v4 24.2.0 or higher together with Adiz 2.0.1 or higher, the consent age set in the Hive SDK will be automatically applied for users under that age.
However, if the user directly calls the AdizConsentManager.setUserPrivacySettings
API before executing Adiz.initialize
, the consent age settings set by the Hive SDK will not apply, and the values set during the AdizConsentManager.setUserPrivacySettings
API call will take precedence.
import com.hive.Adiz
import com.hive.adiz.AdizError
import com.hive.adiz.consent.PrivacySettings
import org.json.JSONObject
fun initialize() {
val isUnderAgeForGDPR = false // Change to true if a child
val settings = PrivacySettings.Builder()
.setTagForUnderAgeOfConsent(isUnderAgeForGDPR)
.build()
AdizConsentManager.setUserPrivacySettings(settings)
Adiz.initialize(activity, object : Adiz.SdkInitializationListener {
override fun onComplete(error: AdizError, jsonData: JSONObject?) {
// ... omitted
}
})
}
import com.hive.Adiz;
import com.hive.adiz.AdizError;
import com.hive.adiz.consent.PrivacySettings;
import org.json.JSONObject;
public void initialize() {
boolean isUnderAgeForGDPR = false; // Change to true if a child
PrivacySettings settings = new PrivacySettings.Builder()
.setTagForUnderAgeOfConsent(isUnderAgeForGDPR)
.build();
AdizConsentManager.setUserPrivacySettings(settings);
Adiz.initialize(activity, new Adiz.SdkInitializationListener() {
@Override
public void onComplete(@NonNull AdizError error, @Nullable JSONObject jsonData) {
if(error.isSuccess()) {
// ... omitted
}
}
});
}
GDPR test device setup¶
The GDPR consent popup is only displayed when the device's IP address is from Europe or the UK. During the development stage, the GDPR consent popup can be forcibly displayed regardless of the IP address to test the popup display, and for this, the GDPR test device must be set up. By setting up a test device in the Hive console, testing can be done easily. The method for setting it up using the setTestDevice
method is as follows, and it is the same as the method for displaying ads on the test device.
- Initialize Adiz by initializing. This is an initialization to check the test device ID, and there is no need to write a GDPR consent message.
Check the logcat output for a message that confirms the device ID. Below is an example message.
- Check the device ID in the message (example:
33BE2250B43518CCDA7DE426D04EE231
). - Copy the device ID.
- Add
AdizGDPRManager.setTestDevice(DEVICE_ID)
before executingAdiz.initialize
in the existing Adiz initialization code. - Write the GDPR consent message and reinitialize Adiz to ensure that the GDPR consent popup appears correctly.
import com.hive.Adiz
import com.hive.adiz.AdizError
import org.json.JSONObject
fun initialize() {
Adiz.setTestDevice("33BE2250B43518CCDA7DE426D04EE231")
Adiz.initialize(activity, object : Adiz.SdkInitializationListener {
override fun onComplete(error: AdizError, jsonData: JSONObject?) {
// ... omitted
}
})
}
import com.hive.Adiz;
import com.hive.adiz.AdizError;
import org.json.JSONObject;
public void initialize() {
Adiz.setTestDevice("33BE2250B43518CCDA7DE426D04EE231");
Adiz.initialize(activity, new Adiz.SdkInitializationListener() {
@Override
public void onComplete(@NonNull AdizError error, @Nullable JSONObject jsonData) {
if(error.isSuccess()) {
// ... omitted
}
}
});
}
COPPA child targeting tag settings¶
According to the Children's Online Privacy Protection Act (COPPA), app developers can specify whether Google should treat content as child-directed by setting the child-targeting tag (tagForChildDirectedTreatment, TFCD) when making ad requests. If you want it to be treated as child-directed, you must call AdizConsentManager.setUserPrivacySettings
before executing Adiz.initialize
. When using Adiz with the Hive SDK, the child-targeting tag is applied automatically, so no additional configuration is necessary.
import com.hive.Adiz
import com.hive.adiz.AdizError
import com.hive.adiz.consent.PrivacySettings
import org.json.JSONObject
fun initialize() {
val isChildDirectedTreatmentForCOPPA = false // Change to true if it is a child
val settings = PrivacySettings.Builder()
.setTagForChildDirectedTreatment(isChildDirectedTreatmentForCOPPA)
.build()
AdizConsentManager.setUserPrivacySettings(settings)
Adiz.initialize(activity, object : Adiz.SdkInitializationListener {
override fun onComplete(error: AdizError, jsonData: JSONObject?) {
// ... omitted
}
})
}
import com.hive.Adiz;
import com.hive.adiz.AdizError;
import com.hive.adiz.consent.PrivacySettings;
import org.json.JSONObject;
public void initialize() {
boolean isChildDirectedTreatmentForCOPPA = false; // Change to true if it is for children
PrivacySettings settings = new PrivacySettings.Builder()
.setTagForChildDirectedTreatment(isChildDirectedTreatmentForCOPPA)
.build();
AdizConsentManager.setUserPrivacySettings(settings);
Adiz.initialize(activity, new Adiz.SdkInitializationListener() {
@Override
public void onComplete(@NonNull AdizError error, @Nullable JSONObject jsonData) {
if(error.isSuccess()) {
// ... omitted
}
}
});
}
Add ad mediation¶
Adiz can display ads using AdMob mediation. To add AdMob mediation, follow the steps below.
Adding AdMob mediation¶
We will proceed with the integration of the ad source in the AdMob console. Follow the table below to continue.
AppLovin | Liftoff Monetize | Meta Audience Network | Pangle | Unity Ads | ironSource | |
---|---|---|---|---|---|---|
Step 1 | Set up AppLovin configuration | Set up Liftoff Monetize configuration | Set up Meta Audience Network configuration | Set up Pangle configuration | Set up Unity Ads configuration | Set up ironSource configuration |
Step 2 | Add AppLovin ad source to AdMob | Add Liftoff Monetize ad source to AdMob | Add Meta Audience Network ad source to AdMob | Add Pangle ad source to AdMob | Add Unity Ads ad source to AdMob | Add ironSource ad source to AdMob |
Step 3 | Add Adiz adapter |
Adding Adiz adapter¶
Add the library dependency to the app-level build.gradle.
dependencies {
// ... (생략)
implementation 'com.com2us.android.adiz:hive-adiz:2.1.3' // 공통 (필수 추가)
implementation 'com.com2us.android.adiz:hive-adiz-adapter-applovin:2.1.3' // AppLovin 연동시 추가
implementation 'com.com2us.android.adiz:hive-adiz-adapter-liftoff:2.1.3' // Liftoff Monetize 연동시 추가
implementation 'com.com2us.android.adiz:hive-adiz-adapter-meta:2.1.3' // Meta Audience Network 연동시 추가
implementation 'com.com2us.android.adiz:hive-adiz-adapter-pangle:2.1.3' // Pangle 연동시 추가
implementation 'com.com2us.android.adiz:hive-adiz-adapter-unityads:2.1.3' // Unity Ads 연동시 추가
implementation 'com.com2us.android.adiz:hive-adiz-adapter-ironsource:2.1.3' // ironSource 연동시 추가
}
Add the configuration code according to the Gradle version used when integrating Pangle or ironSource.
-
If you are using Gradle 7.0 or higher, add the
repository
setting in thedependencyResolutionManagement
section of the project-level settings.gradle. -
If you are using Gradle version below 7.0, add the
repository
setting in the project-level build.gradleallprojects
section.
To check if the Adiz adapter configuration has been applied correctly, run the app and check the configuration list on the Ad Inspector screen.
Adiz initialization¶
This is a mandatory step that must be performed before displaying ads of all types. By initializing Adiz, you can receive the ad keys necessary for displaying ads. If you have test mode activated, you will receive a test key. If you are using the Hive SDK, proceed with Adiz initialization after calling AuthV4.setup
.
val sdkInitializationListener = object : Adiz.SdkInitializationListener {
override fun onComplete(error: AdizError, jsonData: JSONObject?) {
Log.d(TAG, "Adiz initialize complete. error code : ${error.getCode()}, message : ${error.getMessage()}, data : $jsonData")
if(error.isSuccess) {
if(jsonData != null) {
var interstitialKeyList = ArrayList<String>()
var bannerKeyList = ArrayList<String>()
var nativeKeyList = ArrayList<String>()
var rewardedKeyList = ArrayList<String>()
var rewardedInterstitialKeyList = ArrayList<String>()
var appOpenKeyList = ArrayList<String>()
try {
var keysArr = jsonData.getJSONArray("keys")
for (i in 0 until keysArr.length()) {
var unit = keysArr.optJSONObject(i)
// An example of constructing a list of keys where is_default is false if you enter the ad key directly in the game.
if (unit.optBoolean("is_default").not()) {
var hiveAdKey = unit.optString("key")
when (unit.optString("form")) {
"interstitial" -> interstitialKeyList.add(hiveAdKey)
"banner" -> bannerKeyList.add(hiveAdKey)
"native" -> nativeKeyList.add(hiveAdKey)
"rewarded" -> rewardedKeyList.add(hiveAdKey)
"rewarded_interstitial" -> rewardedInterstitialKeyList.add(hiveAdKey)
"app_open" -> appOpenKeyList.add(hiveAdKey)
}
}
}
println("interstitialKeyList $interstitialKeyList")
println("bannerKeyList $bannerKeyList")
println("nativeKeyList $nativeKeyList")
println("rewardedKeyList $rewardedKeyList")
println("rewardedInterstitialKeyList $rewardedInterstitialKeyList")
println("appOpenKeyList $appOpenKeyList")
} catch (e: JSONException) {
//...
}
}
}
}
}
fun initAdiz() {
// General initialization
Adiz.initialize(activity, sdkInitializationListener)
}
fun initAdizForNonGDPR() {
// In cases where GDPR compliance is not addressed
Adiz.initializeForNonGDPR(activity, sdkInitializationListener)
}
Adiz.SdkInitializationListener sdkInitializationListener = new Adiz.SdkInitializationListener() {
@Override
public void onComplete(@NonNull AdizError error, @Nullable JSONObject jsonData) {
if(error.isSuccess()) {
if(jsonData != null) {
ArrayList interstitialKeyList = new ArrayList<String>();
ArrayList bannerKeyList = new ArrayList<String>();
ArrayList nativeKeyList = new ArrayList<String>();
ArrayList rewardedKeyList = new ArrayList<String>();
ArrayList rewardedInterstitialKeyList = new ArrayList<String>();
ArrayList appOpenKeyList = new ArrayList<String>();
try {
JSONArray keysArr = jsonData.optJSONArray("keys");
for(int i = 0; i < keysArr.length(); i++) {
JSONObject unit = keysArr.optJSONObject(i);
if(unit.optBoolean("is_default") == false) {
String hiveAdKey = unit.optString("key");
String form = unit.optString("form");
switch (form) {
case "interstitial":
interstitialKeyList.add(hiveAdKey);
break;
case "banner":
bannerKeyList.add(hiveAdKey);
break;
case "native":
nativeKeyList.add(hiveAdKey);
break;
case "rewarded":
rewardedKeyList.add(hiveAdKey);
break;
case "rewarded_interstitial":
rewardedInterstitialKeyList.add(hiveAdKey);
break;
case "app_open":
appOpenKeyList.add(hiveAdKey);
break;
}
}
}
System.out.println("interstitialKeyList " + interstitialKeyList);
System.out.println("bannerKeyList " + bannerKeyList);
System.out.println("nativeKeyList " + nativeKeyList);
System.out.println("rewardedKeyList " + rewardedKeyList);
System.out.println("rewardedInterstitialKeyList " + rewardedInterstitialKeyList);
System.out.println("appOpenKeyList " + appOpenKeyList);
} catch (Exception e) {
}
}
}
}
};
void initAdiz() {
// General initialization
Adiz.initialize(activity, sdkInitializationListener);
}
void initAdizForNonGDPR() {
// If not responding to GDPR
Adiz.initializeForNonGDPR(activity, sdkInitializationListener);
}
The JSON file received as a callback when executing initialization contains a list of advertisement keys. The list of advertisement keys has the following format.
{
"keys":[
{
"mediation_id":5,
"key":"ca-app-pub-3940256099942544/5354046379",
"form":"rewarded_interstitial",
"is_default":true,
"placement_id":"lobby01"
},
{
"mediation_id":4,
"key":"ca-app-pub-3940256099942544/5224354917",
"form":"rewarded",
"is_default":true,
"placement_id":"game02"
},
{
"mediation_id":3,
"key":"ca-app-pub-3940256099942544/2247696110",
"form":"native",
"is_default":true,
"placement_id":"event01"
},
{
"mediation_id":1,
"key":"ca-app-pub-3940256099942544/1033173712",
"form":"interstitial",
"is_default":true,
"placement_id":"mission01"
},
{
"mediation_id":2,
"key":"ca-app-pub-3940256099942544/6300978111",
"form":"banner",
"is_default":true,
"placement_id":"main01"
},
{
"mediation_id":6,
"key":"ca-app-pub-3940256099942544/9257395921",
"form":"app_open",
"is_default":true,
"placement_id":"appopen01"
}
]
}
When initializing in test mode, you will receive a list of test ad keys even if you have not registered the AdMob ad key in the Hive console. When initializing in production mode, you will receive a list of AdMob ad keys registered in the Hive console.
For each type of advertisement (form
), one advertisement is used as the default advertisement (the advertisement with "is_default":true
). When registering an advertisement type for the first time, the initially registered advertisement becomes the default advertisement. The default advertisement does not require the advertisement key (hiveAdKey
) to be entered when creating the advertisement instance (initialize()
). To change the default advertisement, you must delete the existing default advertisement from the Hive console and register a new advertisement.
Setting up ad callback listener¶
By implementing AdizListener
when creating each ad instance, you can receive callbacks based on the changes in the ad status.
Name | Description | Required Implementation |
---|---|---|
onLoad() | Ad load success | O |
onFail(error: AdizError) | Failure (the reason for failure can be known by error.getCode() and error.getMessage() ) | O |
onShow() | Ad exposure success | O |
onClick() | Ad click | O |
onPaidEvent(adRevenueData: AdRevenueData) | Point in time when receiving a paid event after ad exposure, ad revenue information is provided | O |
onClose() | Ad end
| X |
onRewarded(rewardItem: RewardItem) | Point in time when the user receives a reward after ad exposure in reward-based ads (rewarded , rewarded interstitial ) | X |
var adizListener = object : AdizListener() {
override fun onLoad() {
// Called when the ad is loaded.
// If the ad load is successful, you need to call the ad instance's .show() at the desired point to display the ad.
}
override fun onFail(loadError: AdizError) {
// Called if the ad load failed or the ad display failed for some other reason.
}
override fun onShow() {
// Called when the ad is displayed.
}
override fun onClick() {
// Called when the ad is clicked.
}
override fun onPaidEvent(adRevenueData: AdRevenueData) {
// Called when revenue is generated for the ad.
var revenue = adRevenueData.revenue // Revenue at the time of ad display
var currency = adRevenueData.currency // Currency code for the revenue at the time of ad display
}
override fun onClose() {
// Called when the ad is closed.
// Banner, Native ads do not have an onClose callback.
}
override fun onRewarded(rewardItem: RewardItem) {
// Called when a reward is creaetd for watching the ad in rewarded, rewarded interstitial ads.
var itemType = rewardItem.itemType // Reward item type
var itemAmount = rewardItem.itemAmount // Reward item quantity
}
}
AdizListener adizListener = new AdizListener() {
@Override
public void onLoad() {
// Called when the ad is loaded.
// If the ad load is successful, you need to call the ad instance's .show() at the desired point to display the ad.
}
@Override
public void onFail(@NonNull AdizError loadError) {
// Called if the ad load failed or the ad display failed for some other reason.
}
@Override
public void onShow() {
// Called when the ad is displayed.
}
@Override
public void onClick() {
// Called when the ad is clicked.
}
@Override
public void onPaidEvent(@NonNull AdRevenueData adRevenueData) {
double revenue = adRevenueData.getRevenue(); // Revenue at the time of ad display
String currency = adRevenueData.getCurrency(); // Currency code for the revenue at the time of ad display
}
@Override
public void onClose() {
// Called when the ad is closed.
// Banner, Native ads do not have a close button and therefore do not have an onClose callback.
}
@Override
public void onRewarded(@NonNull RewardItem rewardItem) {
// Called when a reward occurs for watching the ad in rewarded, rewarded interstitial ads.
String rewardType = rewardItem.getItemType(); // Reward item type
int rewardAmount = rewardItem.getItemAmount(); // Reward item quantity
}
};
Error Codes¶
When receiving onFail()
in Adiz.Initialize
and AdizListener
, the AdizError
error codes and error messages are as follows.
Common Code¶
Number | Case | Explanation |
---|---|---|
0 | Success | Success |
Adiz Error Codes¶
Number | Case | Explanation |
---|---|---|
-1 | InvalidParam | Invalid parameter |
-2 | NotSupported | Not supported |
-3 | InProgress | Process in progress |
-4 | Network | Network error |
-5 | NeedInitialize | Initialization required |
-6 | ResponseFail | Response failed |
-7 | Timeout | Network timeout |
-99 | Unknown | Unknown error |
Ad Platform Error Codes¶
Number | Case | Explanation |
---|---|---|
-101 | NeedLoad | Ad did not load |
-102 | NeedReload | Need to reload due to ad exposure time expiration |
-103 | NotEnoughInventory | Mediation response was successful, but no filled ads due to lack of inventory |
-104 | MissingAppId | AppID error for mediation request |
-105 | InternalNetworkError | Mediation network related error |
-106 | InvalidUnitId | Invalid Unit Id |
-107 | MediationNoFill | Mediation adapter failed to process ad request |
-108 | AlreadyLoaded | Already in a loaded state |
-109 | CannotRequestAds | Cannot request ads |
-201 | GdprConsentError | GDPR consent error |
-202 | IsNotPrivacyOptionsRequired | Cannot display GDPR consent popup or it is not required to display |
Ad display and ad termination¶
To display and terminate ads, follow these steps.
- Create an ad instance in the ad class for each type of ad you want to display. If the ad you want to display is not a default ad, you must enter the ad key or placement ID obtained from initialization.
If you do not enter the ad key (hiveAdKey
) or placement ID (placementId
), a default ad instance will be created. The placement ID can be set in the Hive console, and for more details, please refer to the Admob settings page in the console guide. - Load the ad you want to display (
load()
). - Show the loaded ad (
show()
). To re-display the ad, callload()
again and then callshow()
. - To close the ad, call
destroy()
.
Interstitial Ads¶
These are full-screen ads that take up the entire screen.
import android.app.Activity
import android.os.Bundle
import com.hive.adiz.AdizError
import com.hive.adiz.AdizListener
import com.hive.adiz.base.AdizInterstitial
import com.hive.adiz.common.AdRevenueData
class InterstitialExample : Activity() {
var interstitialAd: AdizInterstitial? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
// requestInitAd(this)
}
val adizListener = object : AdizListener() {
override fun onLoad() {
// requestShowAd()
}
override fun onFail(loadError: AdizError) {
var code = loadError.getCode() // error code
var message = loadError.getMessage() // error message
}
override fun onShow() {
//
}
override fun onClick() {
//
}
override fun onPaidEvent(adRevenueData: AdRevenueData) {
var revenue = adRevenueData.revenue // revenue when ad is exposed
var currency = adRevenueData.currency // currency code for revenue when ad is exposed
}
override fun onClose() {
// requestDestroyAd()
}
}
fun requestInitAd(activity: Activity, hiveAdKey: String? = null) {
if(hiveAdKey.isNullOrEmpty()) {
// Create an interstitial ad instance.
interstitialAd = AdizInterstitial.initialize(activity, adizListener)
} else {
// You can create an interstitial ad instance by entering the hiveAdKey.
interstitialAd = AdizInterstitial.initialize(activity, hiveAdKey, adizListener)
}
// requestLoadAd()
}
fun requestInitAdWithPlacementid(activity: Activity, placementId: String? = null) {
if(placementId.isNullOrEmpty()) {
// Create an interstitial ad instance.
interstitialAd = AdizInterstitial.initialize(activity, adizListener)
} else {
// You can create an interstitial ad instance by entering the placementId.
interstitialAd = AdizInterstitial.initializeWithPlacementId(activity, placementId, adizListener)
}
// requestLoadAd()
}
fun requestLoadAd() {
// Load the interstitial ad.
interstitialAd?.let {
if(it.isInitialized()) it.load()
}
}
fun requestShowAd() {
// Expose the interstitial ad.
interstitialAd?.let {
if(it.isLoaded()) it.show()
}
}
fun requestDestroyAd() {
// Remove the interstitial ad.
interstitialAd?.destroy()
}
}
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.hive.adiz.AdizError;
import com.hive.adiz.AdizListener;
import com.hive.adiz.base.AdizInterstitial;
import com.hive.adiz.common.AdRevenueData;
public class InterstitialExample extends Activity {
AdizInterstitial interstitialAd = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
// requestInitAd(this, null);
}
AdizListener adizListener = new AdizListener() {
@Override
public void onLoad() {
// requestShowAd();
}
@Override
public void onFail(@NonNull AdizError loadError) {
int code = loadError.getCode(); // error code
String message = loadError.getMessage(); // error message
}
@Override
public void onShow() {
}
@Override
public void onClick() {
//
}
@Override
public void onClose() {
// requestDestroyAd();
}
@Override
public void onPaidEvent(@NonNull AdRevenueData adRevenueData) {
double revenue = adRevenueData.getRevenue(); // revenue when ad is exposed
String currency = adRevenueData.getCurrency(); // currency code for revenue when ad is exposed
}
};
public void requestInitAd(Activity activity, String hiveAdKey) {
if(TextUtils.isEmpty(hiveAdKey)) {
// Create an interstitial ad instance.
interstitialAd = AdizInterstitial.initialize(activity, adizListener);
} else {
// You can create an interstitial ad instance by entering the hiveAdKey.
interstitialAd = AdizInterstitial.initialize(activity, hiveAdKey, adizListener);
}
// requestLoadAd();
}
public void requestInitAdWithPlacementId(Activity activity, String placementId) {
if(TextUtils.isEmpty(placementId)) {
// Create an interstitial ad instance.
interstitialAd = AdizInterstitial.initialize(activity, adizListener);
} else {
// You can create an interstitial ad instance by entering the placementId.
interstitialAd = AdizInterstitial.initializeWithPlacementId(activity, placementId, adizListener);
}
// requestLoadAd();
}
private void requestLoadAd() {
// Load the interstitial ad.
if(interstitialAd != null && interstitialAd.isInitialized()) interstitialAd.load();
}
private void requestShowAd() {
// Expose the interstitial ad.
if(interstitialAd != null && interstitialAd.isLoaded()) interstitialAd.show();
}
private void requestDestroyAd() {
// Remove the interstitial ad.
if(interstitialAd != null) interstitialAd.destroy();
}
}
Banner Advertising (Banner)¶
This is a banner advertisement that displays a banner of a specific size. The banner advertisement does not receive the onClose()
callback. Therefore, you need to call destroy()
from another location to terminate the advertisement.
BannerSize
follows the standard banner size.
Size Points (Width x Height) | Description | Supported Devices | BannerSize Constant |
---|---|---|---|
320x50 | Banner | Mobile Phones and Tablets | BannerSize.NORMAL |
320x100 | Large Banner | Mobile Phones and Tablets | BannerSize.MEDIUM |
300x250 | IAB Medium Rectangle | Mobile Phones and Tablets | BannerSize.LARGE |
468 x 60 | IAB Full-Size Banner | Tablets | BannerSize.FULL |
PositionType
is either topmost or bottommost. The default value is bottommost.
Alignment | Description | PositionType Constant |
---|---|---|
Top Alignment | Specifies alignment at the top of the screen | PositionType.TOP |
Bottom Alignment (default) | Specifies alignment at the bottom of the screen | PositionType.BOTTOM |
import android.app.Activity
import android.os.Bundle
import com.hive.adiz.AdizError
import com.hive.adiz.AdizListener
import com.hive.adiz.base.AdizBanner
import com.hive.adiz.common.AdRevenueData
import com.hive.adiz.common.BannerSize
import com.hive.adiz.common.PositionType
class BannerExample : Activity() {
var banner: AdizBanner? = null
// Set the banner size.
var bannerSize = BannerSize.NORMAL
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
// requestInitAd(this)
}
val adizListener = object : AdizListener() {
override fun onLoad() {
// requestShowAd()
}
override fun onFail(loadError: AdizError) {
var code = loadError.getCode() // error code
var message = loadError.getMessage() // error message
}
override fun onShow() {
//
}
override fun onClick() {
//
}
override fun onPaidEvent(adRevenueData: AdRevenueData) {
var revenue = adRevenueData.revenue // revenue when ad is exposed
var currency = adRevenueData.currency // currency code for revenue when ad is exposed
}
}
fun requestInitAd(activity: Activity, hiveAdKey: String? = null) {
if(hiveAdKey.isNullOrEmpty()) {
// Create a banner ad instance.
banner = AdizBanner.initialize(activity, bannerSize, adizListener)
} else {
// You can create a banner ad instance by entering the hiveAdKey.
banner = AdizBanner.initialize(activity, hiveAdKey, bannerSize, adizListener)
}
// requestLoadAd()
}
fun requestInitAdWithPlacementId(activity: Activity, placementId: String? = null) {
if(placementId.isNullOrEmpty()) {
// Create a banner ad instance.
banner = AdizBanner.initialize(activity, bannerSize, adizListener)
} else {
// You can create a banner ad instance by entering the placementId.
banner = AdizBanner.initializeWithPlacementId(activity, placementId, bannerSize, adizListener)
}
// requestLoadAd()
}
fun requestLoadAd() {
// Load the banner ad.
banner?.let {
if(it.isInitialized()) it.load()
}
}
fun requestShowAd() {
// Expose the banner ad.
banner?.let {
if(it.isLoaded()) it.show()
}
// Set banner position
/*
var position = PositionType.TOP
banner?.let {
if(it.isLoaded()) it.show(position)
}
*/
}
fun requestDestroyAd() {
// Remove the banner ad.
banner?.destroy()
}
}
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.hive.adiz.AdizError;
import com.hive.adiz.AdizListener;
import com.hive.adiz.base.AdizBanner;
import com.hive.adiz.common.AdRevenueData;
import com.hive.adiz.common.BannerSize;
import com.hive.adiz.common.PositionType;
public class BannerExample extends Activity {
// Set the banner size.
BannerSize bannerSize = BannerSize.NORMAL;
AdizBanner banner = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
// requestInitAd(this, null);
}
AdizListener adizListener = new AdizListener() {
@Override
public void onLoad() {
// requestShowAd();
}
@Override
public void onFail(@NonNull AdizError loadError) {
int code = loadError.getCode(); // error code
String message = loadError.getMessage(); // error message
}
@Override
public void onShow() {
}
@Override
public void onClick() {
//
}
@Override
public void onPaidEvent(@NonNull AdRevenueData adRevenueData) {
double revenue = adRevenueData.getRevenue(); // revenue when ad is exposed
String currency = adRevenueData.getCurrency(); // currency code for revenue when ad is exposed
}
};
public void requestInitAd(Activity activity, String hiveAdKey) {
if(TextUtils.isEmpty(hiveAdKey)) {
// Create a banner ad instance.
banner = AdizBanner.initialize(activity, bannerSize, adizListener);
} else {
// You can create a banner ad instance by entering the hiveAdKey.
banner = AdizBanner.initialize(activity, hiveAdKey, bannerSize, adizListener);
}
// requestLoadAd();
}
public void requestInitAdWithPlacementId(Activity activity, String placementId) {
if(TextUtils.isEmpty(placementId)) {
// Create a banner ad instance.
banner = AdizBanner.initialize(activity, bannerSize, adizListener);
} else {
// You can create a banner ad instance by entering the placementId.
banner = AdizBanner.initializeWithPlacementId(activity, placementId, bannerSize, adizListener);
}
// requestLoadAd();
}
private void requestLoadAd() {
// Load the banner ad.
if(banner != null && banner.isInitialized()) banner.load();
}
private void requestShowAd() {
// Expose the banner ad.
if(banner != null && banner.isLoaded()) banner.show();
// Set banner position
// PositionType position = PositionType.TOP;
// if(banner != null) banner.show(position);
}
private void requestDestroyAd() {
// Remove the banner ad.
if(banner != null) banner.destroy();
}
}
Native Advertising (Native)¶
This is a native advertisement that exposes a native template of a specific size. Native ads are optimized for portrait screens, so it is recommended to use them in vertical games (portrait screen games). Native ads do not receive the onClose()
callback. Therefore, you need to call destroy()
from another location to terminate the ad.
The current template supports small
or medium
sizes.
Template | Alignment | BannerSize Constant |
---|---|---|
small size | Top / Bottom | BannerSize.NORMAL |
medium size | Center (fixed) | BannerSize.MEDIUM |
In the small
template, PositionType
is either top or bottom, and the default is bottom.
Alignment | Description | PositionType Constant |
---|---|---|
Top Alignment | Specifies alignment at the top of the screen | PositionType.TOP |
Bottom Alignment (default) | Specifies alignment at the bottom of the screen | PositionType.BOTTOM |
The medium
template does not allow for alignment selection and uses center alignment by default.
import android.app.Activity
import android.os.Bundle
import com.hive.adiz.AdizError
import com.hive.adiz.AdizListener
import com.hive.adiz.base.AdizNative
import com.hive.adiz.common.AdRevenueData
import com.hive.adiz.common.BannerSize
class NativeAdExampleKT : Activity() {
var nativeAd: AdizNative? = null
// Set the banner size.
var bannerSize = BannerSize.NORMAL
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
// requestInitAd(this)
}
val adizListener = object : AdizListener() {
override fun onLoad() {
// requestShowAd()
}
override fun onFail(loadError: AdizError) {
var code = loadError.getCode() // Error code
var message = loadError.getMessage() // Error message
}
override fun onShow() {
//
}
override fun onClick() {
//
}
override fun onPaidEvent(adRevenueData: AdRevenueData) {
var revenue = adRevenueData.revenue // Revenue when ad is shown
var currency = adRevenueData.currency // Currency code for revenue when ad is shown
}
}
fun requestInitAd(activity: Activity, hiveAdKey: String? = null) {
if(hiveAdKey.isNullOrEmpty()) {
// Create a native ad instance.
nativeAd = AdizNative.initialize(activity, bannerSize, adizListener)
} else {
// You can create a native ad instance by entering the hiveAdKey.
nativeAd = AdizNative.initialize(activity, hiveAdKey, bannerSize, adizListener)
}
// requestLoadAd()
}
fun requestInitAdWithPlacementId(activity: Activity, placementId: String? = null) {
if(placementId.isNullOrEmpty()) {
// Create a native ad instance.
nativeAd = AdizNative.initialize(activity, bannerSize, adizListener)
} else {
// You can create a native ad instance by entering the placementId.
nativeAd = AdizNative.initializeWithPlacementId(activity, placementId, bannerSize, adizListener)
}
// requestLoadAd()
}
fun requestLoadAd() {
// Load the native ad.
nativeAd?.let {
if(it.isInitialized()) it.load()
}
}
fun requestShowAd() {
// Expose the native ad.
nativeAd?.let {
if(it.isLoaded()) it.show()
}
// Set banner position
/*
var position = PositionType.TOP
nativeAd?.let {
if(it.isLoaded()) it.show(position)
}
*/
}
fun requestDestroyAd() {
// Remove the native ad.
nativeAd?.destroy()
}
}
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.hive.adiz.AdizError;
import com.hive.adiz.AdizListener;
import com.hive.adiz.base.AdizNative;
import com.hive.adiz.common.AdRevenueData;
import com.hive.adiz.common.BannerSize;
import com.hive.adiz.common.PositionType;
public class NativeAdExample extends Activity {
// Set the banner size.
BannerSize bannerSize = BannerSize.NORMAL;
AdizNative nativeAd = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
// requestInitAd(this, null);
}
AdizListener adizListener = new AdizListener() {
@Override
public void onLoad() {
// requestShowAd();
}
@Override
public void onFail(@NonNull AdizError loadError) {
int code = loadError.getCode(); // Error code
String message = loadError.getMessage(); // Error message
}
@Override
public void onShow() {
}
@Override
public void onClick() {
//
}
@Override
public void onPaidEvent(@NonNull AdRevenueData adRevenueData) {
double revenue = adRevenueData.getRevenue(); // Revenue when ad is shown
String currency = adRevenueData.getCurrency(); // Currency code for revenue when ad is shown
}
};
public void requestInitAd(Activity activity, String hiveAdKey) {
if(TextUtils.isEmpty(hiveAdKey)) {
// Create a native ad instance. (If no HiveAdKey is entered, the instance is created with the default key set to is_default=true, which was received during the initialization of Hive Adiz.)
nativeAd = AdizNative.initialize(activity, bannerSize, adizListener);
} else {
// You can create a native ad instance by entering the hiveAdKey.
nativeAd = AdizNative.initialize(activity, hiveAdKey, bannerSize, adizListener);
}
// requestLoadAd();
}
public void requestInitAdWithPlacementId(Activity activity, String placementId) {
if(TextUtils.isEmpty(placementId)) {
// Create a native ad instance. (If no HiveAdKey is entered, the instance is created with the default key set to is_default=true, which was received during the initialization of Hive Adiz.)
nativeAd = AdizNative.initialize(activity, bannerSize, adizListener);
} else {
// You can create a native ad instance by entering the placementId.
nativeAd = AdizNative.initializeWithPlacementId(activity, placementId, bannerSize, adizListener);
}
// requestLoadAd();
}
private void requestLoadAd() {
// Load the native ad.
if(nativeAd != null && nativeAd.isInitialized()) nativeAd.load();
}
private void requestShowAd() {
// Display the native ad.
if(nativeAd != null && nativeAd.isLoaded()) nativeAd.show();
// Set banner position
// PositionType position = PositionType.TOP;
// if(nativeAd != null && nativeAd.isLoaded()) nativeAd.show(position);
}
private void requestDestroyAd() {
// Remove the native ad.
if(nativeAd != null) nativeAd.destroy();
}
}
Rewarded Ads¶
This is a rewarded ad where users receive rewards for watching the ad for a certain amount of time. Once the reward is granted, the reward item information is received through the onRewarded()
callback.
import android.app.Activity
import android.os.Bundle
import com.hive.adiz.AdizError
import com.hive.adiz.AdizListener
import com.hive.adiz.base.AdizRewarded
import com.hive.adiz.common.AdRevenueData
class RewardedExample : Activity() {
var rewardedAd: AdizRewarded? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
// requestInitAd(this)
}
val adizListener = object : AdizListener() {
override fun onLoad() {
// requestShowAd()
}
override fun onFail(loadError: AdizError) {
var code = loadError.getCode() // Error code
var message = loadError.getMessage() // Error message
}
override fun onShow() {
//
}
override fun onClick() {
//
}
override fun onPaidEvent(adRevenueData: AdRevenueData) {
var revenue = adRevenueData.revenue // Revenue when ad is shown
var currency = adRevenueData.currency // Currency code for revenue when ad is shown
}
override fun onClose() {
// requestDestroyAd()
}
override fun onRewarded(rewardItem: RewardItem) {
var itemType = rewardItem.itemType // Reward item type
var itemAmount = rewardItem.itemAmount // Reward item quantity
}
}
fun requestInitAd(activity: Activity, hiveAdKey: String? = null) {
if(hiveAdKey.isNullOrEmpty()) {
// Create a rewarded ad instance.
rewardedAd = AdizRewarded.initialize(activity, adizListener)
} else {
// You can create a rewarded ad instance by entering the hiveAdKey.
rewardedAd = AdizRewarded.initialize(activity, hiveAdKey, adizListener)
}
// requestLoadAd()
}
fun requestInitAdWithPlacementId(activity: Activity, placementId: String? = null) {
if(placementId.isNullOrEmpty()) {
// Create a rewarded ad instance.
rewardedAd = AdizRewarded.initialize(activity, adizListener)
} else {
// You can create a rewarded ad instance by entering the placementId.
rewardedAd = AdizRewarded.initializeWithPlacementId(activity, placementId, adizListener)
}
// requestLoadAd()
}
fun requestLoadAd() {
// Load the rewarded ad.
rewardedAd?.let {
if(it.isInitialized()) it.load()
}
}
fun requestShowAd() {
// Display the rewarded ad.
rewardedAd?.let {
if(it.isLoaded()) it.show()
}
}
fun requestDestroyAd() {
// Remove the rewarded ad.
rewardedAd?.destroy()
}
}
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.hive.adiz.AdizError;
import com.hive.adiz.AdizListener;
import com.hive.adiz.base.AdizRewarded;
import com.hive.adiz.common.AdRevenueData;
public class RewardedExample extends Activity {
AdizRewarded rewardedAd = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
// requestInitAd(this, null);
}
AdizListener adizListener = new AdizListener() {
@Override
public void onLoad() {
// requestShowAd();
}
@Override
public void onFail(@NonNull AdizError loadError) {
int code = loadError.getCode(); // Error code
String message = loadError.getMessage(); // Error message
}
@Override
public void onShow() {
//
}
@Override
public void onClick() {
//
}
@Override
public void onPaidEvent(@NonNull AdRevenueData adRevenueData) {
double revenue = adRevenueData.getRevenue(); // Revenue when ad is shown
String currency = adRevenueData.getCurrency(); // Currency code for revenue when ad is shown
}
@Override
public void onClose() {
// requestDestroyAd();
}
@Override
public void onRewarded(@NonNull RewardItem rewardItem) {
String rewardType = rewardItem.getItemType(); // Reward item type
int rewardAmount = rewardItem.getItemAmount(); // Reward item quantity
}
};
public void requestInitAd(Activity activity, String hiveAdKey) {
if(TextUtils.isEmpty(hiveAdKey)) {
// Create a rewarded ad instance. (If no HiveAdKey is entered, the instance is created with the default key (is_default=true), which was received during the initialization of Hive Adiz.)
rewardedAd = AdizRewarded.initialize(activity, adizListener);
} else {
// You can create a rewarded ad instance by entering the hiveAdKey.
rewardedAd = AdizRewarded.initialize(activity, hiveAdKey, adizListener);
}
// requestLoadAd();
}
public void requestInitAdWithPlacementId(Activity activity, String placementId) {
if(TextUtils.isEmpty(placementId)) {
// Create a rewarded ad instance. (If no HiveAdKey is entered, the instance is created with the default key (is_default=true), which was received during the initialization of Hive Adiz.)
rewardedAd = AdizRewarded.initialize(activity, adizListener);
} else {
// You can create a rewarded ad instance by entering the placementId.
rewardedAd = AdizRewarded.initializeWithPlacementId(activity, placementId, adizListener);
}
// requestLoadAd();
}
private void requestLoadAd() {
// Load the rewarded ad.
if(rewardedAd != null && rewardedAd.isInitialized()) rewardedAd.load();
}
private void requestShowAd() {
// Display the rewarded ad.
if(rewardedAd != null && rewardedAd.isLoaded()) rewardedAd.show();
}
private void requestDestroyAd() {
// Remove the rewarded ad.
if(rewardedAd != null) rewardedAd.destroy();
}
}
Rewarded Interstitial¶
This is a rewarded interstitial ad where users receive rewards for watching the ad for a certain period of time. Once the reward is granted, the reward item information is received through the onRewarded()
callback.
import android.app.Activity
import android.os.Bundle
import com.hive.adiz.AdizError
import com.hive.adiz.AdizListener
import com.hive.adiz.base.AdizRewardedInterstitial
import com.hive.adiz.common.AdRevenueData
import com.hive.adiz.rewarded.RewardItem
class RewardedInterstitialExample : Activity() {
var rewardedInterstitialAd: AdizRewardedInterstitial? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
// requestInitAd(this)
}
val adizListener = object : AdizListener() {
override fun onLoad() {
// requestShowAd()
}
override fun onFail(loadError: AdizError) {
var code = loadError.getCode() // Error code
var message = loadError.getMessage() // Error message
}
override fun onShow() {
//
}
override fun onClick() {
//
}
override fun onPaidEvent(adRevenueData: AdRevenueData) {
var revenue = adRevenueData.revenue // Revenue generated when ad is shown
var currency = adRevenueData.currency // Currency code for revenue when ad is shown
}
override fun onClose() {
// requestDestroyAd()
}
override fun onRewarded(rewardItem: RewardItem) {
var itemType = rewardItem.itemType // Reward item type
var itemAmount = rewardItem.itemAmount // Reward item quantity
}
}
fun requestInitAd(activity: Activity, hiveAdKey: String? = null) {
if(hiveAdKey.isNullOrEmpty()) {
// Creates an instance of rewarded interstitial ad.
rewardedInterstitialAd = AdizRewardedInterstitial.initialize(activity, adizListener)
} else {
// You can create an instance of rewarded interstitial ad by entering the hiveAdKey.
rewardedInterstitialAd = AdizRewardedInterstitial.initialize(activity, hiveAdKey, adizListener)
}
// requestLoadAd()
}
fun requestInitAdWithPlacementId(activity: Activity, placementId: String? = null) {
if(placementId.isNullOrEmpty()) {
// Creates an instance of rewarded interstitial ad.
rewardedInterstitialAd = AdizRewardedInterstitial.initialize(activity, adizListener)
} else {
// You can create an instance of rewarded interstitial ad by entering the placementId.
rewardedInterstitialAd = AdizRewardedInterstitial.initializeWithPlacementId(activity, placementId, adizListener)
}
// requestLoadAd()
}
fun requestLoadAd() {
// Loads the rewarded interstitial ad.
rewardedInterstitialAd?.let {
if(it.isInitialized()) it.load()
}
}
fun requestShowAd() {
// Displays the rewarded interstitial ad.
rewardedInterstitialAd?.let {
if(it.isLoaded()) it.show()
}
}
fun requestDestroyAd() {
// Removes the rewarded interstitial ad.
rewardedInterstitialAd?.destroy()
}
}
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.hive.adiz.AdizError;
import com.hive.adiz.AdizListener;
import com.hive.adiz.base.AdizRewardedInterstitial;
import com.hive.adiz.common.AdRevenueData;
import com.hive.adiz.rewarded.RewardItem;
public class RewardedInterstitialExample extends Activity {
AdizRewardedInterstitial rewardedInterstitialAd = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
// requestInitAd(this, null);
}
AdizListener adizListener = new AdizListener() {
@Override
public void onLoad() {
// requestShowAd();
}
@Override
public void onFail(@NonNull AdizError loadError) {
int code = loadError.getCode(); // Error code
String message = loadError.getMessage(); // Error message
}
@Override
public void onShow() {
//
}
@Override
public void onClick() {
//
}
@Override
public void onPaidEvent(@NonNull AdRevenueData adRevenueData) {
double revenue = adRevenueData.getRevenue(); // Revenue generated when ad is shown
String currency = adRevenueData.getCurrency(); // Currency code for when ad is shown
}
@Override
public void onClose() {
// requestDestroyAd();
}
@Override
public void onRewarded(@NonNull RewardItem rewardItem) {
String rewardType = rewardItem.getItemType(); // Reward item type
int rewardAmount = rewardItem.getItemAmount(); // Reward item quantity
}
};
public void requestInitAd(Activity activity, String hiveAdKey) {
if(TextUtils.isEmpty(hiveAdKey)) {
// Creates an instance of rewarded interstitial ad (If the ad key (HiveAdKey) is not entered, the instance will be created with the default key (is_default=true) during Hive Adiz initialization.)
rewardedInterstitialAd = AdizRewardedInterstitial.initialize(activity, adizListener);
} else {
// You can create an instance of rewarded interstitial ad by entering the hiveAdKey.
rewardedInterstitialAd = AdizRewardedInterstitial.initialize(activity, hiveAdKey, adizListener);
}
// requestLoadAd();
}
public void requestInitAdWithPlacementId(Activity activity, String placementId) {
if(TextUtils.isEmpty(placementId)) {
// Creates an instance of rewarded interstitial ad (If the ad key (HiveAdKey) is not entered, the instance will be created with the default key (is_default=true) during Hive Adiz initialization.)
rewardedInterstitialAd = AdizRewardedInterstitial.initialize(activity, adizListener);
} else {
// You can create an instance of rewarded interstitial ad by entering the placementId.
rewardedInterstitialAd = AdizRewardedInterstitial.initializeWithPlacementId(activity, placementId, adizListener);
}
// requestLoadAd();
}
private void requestLoadAd() {
// Loads the rewarded interstitial ad.
if(rewardedInterstitialAd != null && rewardedInterstitialAd.isInitialized()) rewardedInterstitialAd.load();
}
private void requestShowAd() {
// Displays the rewarded interstitial ad.
if(rewardedInterstitialAd != null && rewardedInterstitialAd.isLoaded()) rewardedInterstitialAd.show();
}
private void requestDestroyAd() {
// Removes the rewarded interstitial ad.
if(rewardedInterstitialAd != null) rewardedInterstitialAd.destroy();
}
}
App Open Ads (AppOpen)¶
This is an app opening ad that displays pre-loaded (load()
) ads when the app state changes from background to foreground. If you call show()
after 3 hours have passed since the ad was loaded, it will automatically reload the ad and then display it. Once an ad has been displayed at least once, it will not be automatically reloaded.
import android.app.Activity
import android.os.Bundle
import com.hive.adiz.AdizError
import com.hive.adiz.AdizListener
import com.hive.adiz.base.AdizAppOpen
import com.hive.adiz.common.AdRevenueData
class AppOpenExample : Activity() {
var appOpen: AdizAppOpen? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
// requestInitAd(this)
}
val adizListener = object : AdizListener() {
override fun onLoad() {
//
}
override fun onFail(loadError: AdizError) {
var code = loadError.getCode() // Error code
var message = loadError.getMessage() // Error message
}
override fun onShow() {
//
}
override fun onClick() {
//
}
override fun onPaidEvent(adRevenueData: AdRevenueData) {
var revenue = adRevenueData.revenue // Revenue when ad is shown
var currency = adRevenueData.currency // Currency code for revenue when ad is shown
}
override fun onClose() {
// requestDestroyAd()
}
}
fun requestInitAd(activity: Activity, hiveAdKey: String? = null) {
if(hiveAdKey.isNullOrEmpty()) {
// Creates an app opening ad instance.
appOpen = AdizAppOpen.initialize(activity, adizListener)
} else {
// You can create an app opening ad instance by entering the hiveAdKey.
appOpen = AdizAppOpen.initialize(activity, hiveAdKey, adizListener)
}
// requestLoadAd()
}
fun requestInitAdWithPlacementId(activity: Activity, placementId: String? = null) {
if(placementId.isNullOrEmpty()) {
// Creates an app opening ad instance.
appOpen = AdizAppOpen.initialize(activity, adizListener)
} else {
// You can create an app opening ad instance by entering the placementId.
appOpen = AdizAppOpen.initializeWithPlacementId(activity, placementId, adizListener)
}
// requestLoadAd()
}
fun requestLoadAd() {
// Loads the app opening ad. After loading is complete, the ad will be automatically displayed when the app moves from background to foreground.
// Once the ad is displayed at least once, it will not be re-displayed, so if you want to continue displaying ads, you need to call appOpen.load() again in the onClose() callback.
appOpen?.let {
if(it.isInitialized()) it.load()
}
}
fun requestDestroyAd() {
// Removes the app opening ad.
appOpen?.destroy()
}
}
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.hive.adiz.AdizError;
import com.hive.adiz.AdizListener;
import com.hive.adiz.base.AdizAppOpen;
import com.hive.adiz.common.AdRevenueData;
public class AppOpenExample extends Activity {
AdizAppOpen appOpen = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
// requestInitAd(this, null);
}
AdizListener adizListener = new AdizListener() {
@Override
public void onLoad() {
//
}
@Override
public void onFail(@NonNull AdizError loadError) {
int code = loadError.getCode(); // Error code
String message = loadError.getMessage(); // Error message
}
@Override
public void onShow() {
//
}
@Override
public void onClick() {
//
}
@Override
public void onPaidEvent(@NonNull AdRevenueData adRevenueData) {
double revenue = adRevenueData.getRevenue(); // Revenue when ad is shown
String currency = adRevenueData.getCurrency(); // Currency code for revenue when ad is shown
}
@Override
public void onClose() {
// requestDestroyAd();
}
};
public void requestInitAd(Activity activity, String hiveAdKey) {
if(TextUtils.isEmpty(hiveAdKey)) {
// Creates an app opening ad instance. (If the ad key (HiveAdKey) is not entered, the instance will be created with the default key (is_default=true) during Hive Adiz initialization.)
appOpen = AdizAppOpen.initialize(activity, adizListener);
} else {
// You can create an app opening ad instance by entering the hiveAdKey.
appOpen = AdizAppOpen.initialize(activity, hiveAdKey, adizListener);
}
// requestLoadAd();
}
public void requestInitAdWithPlacementId(Activity activity, String placementId) {
if(TextUtils.isEmpty(placementId)) {
// Creates an app opening ad instance. (If the ad key (HiveAdKey) is not entered, the instance will be created with the default key (is_default=true) during Hive Adiz initialization.)
appOpen = AdizAppOpen.initialize(activity, adizListener);
} else {
// You can create an app opening ad instance by entering the placementId.
appOpen = AdizAppOpen.initializeWithPlacementId(activity, placementId, adizListener);
}
// requestLoadAd();
}
private void requestLoadAd() {
// Loads the app opening ad.
if(appOpen != null && appOpen.isInitialized()) appOpen.load();
}
private void requestDestroyAd() {
// Removes the app opening ad.
if(appOpen != null) appOpen.destroy();
}
}