Skip to content

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

    dependencies {
        implementation 'com.com2us.android.adiz:hive-adiz:2.1.0'
    }
 

To support Java 8 features, add the following under the android settings in the app-level Gradle file of the module.

android {
    // ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

 

AndroidManifest.xml file, enter the 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 2 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 test mode so that clicking on test ads does not charge advertisers. When test mode is activated, only test ads will be displayed. In test mode, test ads will be displayed even without entering the AdMob ad key in the console. Deactivate 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 Test Device Management 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 creating 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 Test Device Management section of the console guide.

  • Use the Adiz class's setTestDevice() method:
    Refer to the example code below.

Note

If you conduct tests displaying actual ads without registering a test device, it may be considered invalid traffic, resulting in your AdMob account being blocked and ads no longer being displayed. When you register a test device, "Test Mode" or "Test Ad" (native ads) will be shown during ad display. You must deactivate the test device during commercial distribution.


Banner, interstitial ads, or rewarded ads


Native Advertising


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 checked in the following two ways.

  • Check the Logcat logs after calling Adiz.Initialize():

    Use new
    ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
    
  • After calling Adiz.Initialize(), regardless of the ad type, call initialize()load() and check the Logcat logs:

    I/Ads: Use RequestConfiguration.Builder.setTestDeviceIds(Arrays.asList("33BE2250B43518CCDA7DE426D04EE231")) to get test ads on this device.
    


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 provides the reason for failure if the ad fails to display. You can also specify a particular ad network to check if the ads are displaying correctly, and if there are issues, you can debug at the code level. This entire process is conducted 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.

import com.hive.adiz.utils.AdizDeveloperTool

AdizDeveloperTool.openAdInspector(activity)
import com.hive.adiz.utils.AdizDeveloperTool;

AdizDeveloperTool.openAdInspector(activity);


Adiz AppID settings

Set the Adiz AppID that was registered in the console AppCenter. If not set, the AndroidManifest.xml package name will be used.

Adiz.setAppId("YOUR_APPID")
Adiz.setAppId("YOUR_APPID");

Hive Console server settings

Set up the Hive console server to use. The default is REAL. Even if you use a 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
Adiz.setZone(AdizConfiguration.ZoneType.REAL)
Adiz.setZone(AdizConfiguration.ZoneType.REAL);

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.

Writing GDPR nessage

Access the Google AdMob console to write a GDPR message. Before writing the GDPR message, please refer to the GDPR Message Writing Guide.

If you have created a GDPR message, the GDPR consent popup will automatically appear when Adiz is initialized.

Implementation of GDPR consent/withdrawal function

The items in the GDPR consent popup must provide a modification function so that users can change their consent status at any time. For example, a user may initially not consent to GDPR but later wish to consent again to view personalized ads, or conversely, a user may have initially consented to GDPR but now wishes to withdraw their consent because they no longer want to provide personal information. To address these situations, app developers must implement a function to either re-consent to each item or withdraw existing consent. To implement the GDPR consent/withdrawal function, follow these steps.

  1. Implement a button UI in the app that can reload the GDPR consent popup.
  2. When implementing Adiz initialization, call isPrivacyOptionsRequired() to display the button UI to users accessing from Europe and the UK, and not display it for others. If a user from Europe or the UK clicks the button, call showPrivacyOptionsForm to reload the GDPR consent popup. This way, users can modify their consent for GDPR details at any time by pressing a button like "Manage Options" in the app. The showPrivacyOptionsForm 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
                                    // Determine 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 as 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
            // Determine 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. (Calls showPrivacyOptionsForm() to show the GDPR consent popup when the button is clicked)
                showGDPRConsentPopupButton();
            } else {
                // Do not display the button in the app.
                // Other processing 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 subjects of limited data processing when making advertising requests. For apps targeting children, you can set the user as under the age of consent using AdizConsentManager.setUserPrivacySettings. Although there are some differences among European countries, GDPR defines the age requiring parental consent as under 16. The under age of consent setting must be configured before executing Adiz.initialize.

Warning

Set the setTagForUnderAgeOfConsent tag for GDPR consent age and the setTagForChildDirectedTreatment setting for COPPA children simultaneously to true, the COPPA children setting setTagForChildDirectedTreatment will take precedence, so do not set them both to true and use them.

Note

When using Hive SDK v4 24.2.0 or higher along with Adiz 2.0.1 or higher, the consent age setting from the Hive SDK is automatically applied for users under the consent age, so there is no need to call AdizConsentManager.setUserPrivacySettings.

 

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 will only be displayed if the device's IP address is from Europe or the UK. During the development phase, the GDPR consent popup can be forced to display regardless of the IP address, allowing for testing of the popup display. To do this, you need to set up a GDPR test device. Setting up a test device in the Hive console makes testing easy. The method to set it up using the setTestDevice method is as follows, and it is the same as displaying ads on the test device.

  1. Initialize Adiz by initializing. This is an initialization to check the test device ID and does not require writing a GDPR consent message.
  2. Check the logcat output for a message that confirms the device ID. Below is an example message.

    Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
    
  3. Check the message for the device ID (example: 33BE2250B43518CCDA7DE426D04EE231).
  4. Copy the device ID.
  5. Add AdizGDPRManager.setTestDevice(DEVICE_ID) before executing Adiz.initialize in the existing Adiz initialization code.
  6. 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

In accordance with 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 wish for it to be treated as child-directed, you must call AdizConsentManager.setUserPrivacySettings before executing Adiz.initialize. When using Adiz in conjunction with the Hive SDK, the child-targeting tag is automatically applied, so no separate configuration is needed.

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 for children

        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 sources in the AdMob console. Follow the table below to proceed.

AppLovin Pangle Unity Ads Meta
Step 1 Set up AppLovin configuration Set up Pangle configuration Set up Unity Ads configuration Set up Meta configuration
Step 2 Add AppLovin ad source to AdMob Add Pangle ad source to AdMob Add Unity Ads ad source to AdMob Add Meta 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.0.1' // Common (required addition) 

    implementation 'com.com2us.android.adiz:hive-adiz-adapter-applovin:2.0.1' // Add when integrating AppLovin
    implementation 'com.com2us.android.adiz:hive-adiz-adapter-pangle:2.0.1' // Add when integrating Pangle
    implementation 'com.com2us.android.adiz:hive-adiz-adapter-unityads:2.0.1' // Add when integrating Unity Ads
    implementation 'com.com2us.android.adiz:hive-adiz-adapter-meta:2.0.1' // Add when integrating Meta
}

 

When integrating Pangle, add the following settings. If you are using Gradle 7.0 or higher, add the repository setting in the dependencyResolutionManagement section of the project-level settings.gradle.


// When using Gradle 7.0 or higher, configure settings.gradle

dependencyResolutionManagement {
    repositories {
        maven { url 'https://artifact.bytedance.com/repository/pangle/' } // Add when integrating Pangle
    }
}

 

If you are using Gradle version below 7.0, add the repository setting in the allprojects section of the project-level build.gradle file.


// Configuration for build.gradle when using Gradle below 7.0

allprojects {
    repositories {
        maven {
            url 'https://artifact.bytedance.com/repository/pangle' // Add when integrating Pangle
        }

    }
}

 

To verify that 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 any type of advertisement. By initializing Adiz, you will receive the advertisement key necessary for displaying ads. If you are in test mode, 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 there is no response to GDPR
    Adiz.initializeForNonGDPR(activity, sdkInitializationListener);
}

 

The JSON file received as a callback during initialization contains a list of ad keys. The list of ad 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 the first advertisement of any type is registered, that advertisement becomes the default advertisement. The default advertisement does not require the advertisement key (hiveAdKey) to be entered when creating an advertisement instance (initialize()). To change the default advertisement, you need to 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 changes in the ad's status.

Name Description Required Implementation
onLoad() Ad load success O
onFail(error: AdizError) Failure (the reason for failure can be known via error.getCode() and error.getMessage()) O
onShow() Ad display success O
onClick() Ad click O
onPaidEvent(adRevenueData: AdRevenueData) The point at which a paid event is received after ad exposure, and ad revenue information is conveyed O
onClose() Ad termination
  • After the ad is terminated, to display the same ad instance again, load() must be called again followed by show().
  • To no longer display ads, call destroy() to remove the ad instance.
X
onRewarded(rewardItem: RewardItem) The point at which 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 needed
-6 ResponseFail Response failed
-7 Timeout Network timeout
-99 Unknown Unknown error

Advertising 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 in a state where it does not need to be displayed

Ad display and ad termination

To display and terminate ads, follow these steps.

  1. 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.
  2. Load the ad you want to display (load()).
  3. Display the loaded ad (show()). To re-display the ad, call load() again and then call show().
  4. To close the ad, call destroy().

Interstitial ads

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

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 Point (Width x Height) Description Supported Targets 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 the topmost or the bottommost. The default value is the 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

This is a native advertisement that exposes a native template of a specific size. Native ads are optimized for vertical screens, so it is recommended to use them in vertical games (portrait screen games). Native ads do not receive the onClose() callback. Therefore, you must call destroy() from another location to close 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 can be either top or bottom, with the default being 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)) {
                        // 기본 키가 is_default=true로 설정된 상태로 Hive Adiz 초기화 중 수신된 기본 키로 인스턴스가 생성됩니다. (HiveAdKey가 입력되지 않은 경우, 기본 키로 인스턴스가 생성됩니다.)
                        nativeAd = AdizNative.initialize(activity, bannerSize, adizListener);
                } else {
                        // 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 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.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 opening ads (AppOpen)

This is an app opening ad that displays pre-loaded (load()) ads when the app state changes from background to foreground. If show() is called 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 shown at least once, it will not automatically reload.

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