Hive Adiz Android
Hive Adiz Android is an advertising module for Android provided by Hive to make it easier to use the advertising exposure features offered by AdMob. The types of advertisements provided by Hive Adiz Android are as follows:
- Interstitial ads
- Banner ads
- Native ads
- Rewarded ads
- Rewarded Interstitial ads
- App Opening ads
To install and use Hive Adiz Android, please refer to the guide below in order.
Installation
Add the Hive Adiz library item to the app-level Gradle file (app/build.gradle) of your module.
1 2 3 4 5 |
dependencies { implementation 'com.com2us.android.adiz:hive-adiz:2.0.1' } |
To support Java 8 features, add the following to your module’s app-level Gradle file with the android
setting.
1 2 3 4 5 6 7 8 9 |
android { // ... compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } |
Enter your AdMobId
(in the format ca-app-pub-XXXXX~YYYYY) in the AndroidManifest.xml file.
1 2 3 4 5 6 7 8 9 10 |
<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 Hive Adiz are already included in the Adiz module. Therefore, there is no need to add Proguard rules to your project.
To display video ads, hardware acceleration must be enabled. Add the following settings for hardware acceleration in the AndroidManifest.xml file. Adding to the application
tag will use hardware acceleration for the entire application. Adding to the activity
tag will use hardware acceleration only for the specific Activity
where you want to display ads.
1 2 3 4 5 6 |
<application android:hardwareAccelerated="true"> <!-- For activities that use ads, hardwareAcceleration should be true. --> <activity android:hardwareAccelerated="true" /> </application> |
Setup Test Ads
Hive Adiz allows you to display test ads in two ways.
- Enable test mode: Only display test ads issued by AdMob.
- Register test devices and display ads: Display real ads for testing purposes. Register the devices to display test ads to ensure no invalid traffic occurs during testing.
Enable Test Mode
During the development phase, enable test mode so that clicks on test ads do not incur charges to advertisers. When test mode is enabled, only AdMob test ads are displayed. In test mode, you do not need to enter the AdMob ad key in the Hive console to display test ads. Disable test mode for commercial distribution.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import com.hive.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) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import com.hive.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); |
Setting up test devices for ad display
You should register a test device to display test ads in the following situations:
- When testing if the AdMob ad key registered in the Hive console works properly
- When you want to ensure the GDPR consent popup is working correctly after you wrote a GDPR message
- When you need to run the Ad Inspector to analyze and debug ad requests
Testing with real ads without registering a test device may be considered invalid traffic, leading to your AdMob account being blocked and no longer being able to display ads. When you register a test device, “Test Mode” or “Test Ad” (for native ads) will be displayed during ad display. Test devices should be disabled for production deployment.
Banner, Interstitial, or Rewarded Ad
To register a test device, first, identify your test device ID. You can find the test device ID (e.g., 33BE2250B43518CCDA7DE426D04EE231
) using the following two methods:
- After calling
Adiz.Initialize()
, check the Logcat log:
Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
- After calling
Adiz.Initialize()
, regardless of the ad type, callinitialize()
→load()
, then check the Logcat log:
I/Ads: Use RequestConfiguration.Builder.setTestDeviceIds(Arrays.asList("33BE2250B43518CCDA7DE426D04EE231")) to get test ads on this device."
After identifying the test device ID, add the line Adiz.setTestDevice(DEVICE_ID)
before executing Adiz.initialize
in the existing Hive Adiz initialization code. Replace DEVICE_ID
with the copied test device ID.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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?) { // ... skipped } }) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
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()) { // ... skipped } } }); } |
Using the Ad Inspector
The Ad Inspector is an in-app overlay tool that analyzes the process of requesting and displaying real ads on a test device in real-time. It informs you of the time it took to load the ad and, if the display failed, provides the reason for the failure. Additionally, you can specify a certain ad network to check if ads are being displayed correctly, and if there are issues, you can debug at the code level. All these processes are conducted with the Ad Inspector UI. It is included in Google Mobile Ads SDK Android 20.0.0 and above, and can be used by calling AdizDeveloperTool.openAdInspector
.
To use the Ad Inspector, the following two conditions must be met:
- Set up the test device with
Adiz.setTestDevice
as per Setting up test devices - Complete initialization with
Adiz.Initialize
as per Initialization
1 2 3 4 5 |
import com.hive.adiz.utils.AdizDeveloperTool AdizDeveloperTool.openAdInspector(activity) |
1 2 3 4 5 |
import com.hive.adiz.utils.AdizDeveloperTool; AdizDeveloperTool.openAdInspector(activity); |
Setting Hive Adiz AppID
Set the Hive Adiz AppID you registered in the Hive console AppCenter. If not set, the AndroidManifest.xml package name is used.
1 2 3 |
Adiz.setAppId("YOUR_APPID") |
1 2 3 |
Adiz.setAppId("YOUR_APPID"); |
Setting Hive Console Server
Set the Hive console server you want to use. The default is REAL
. Even if you use the commercial server, test ads are displayed if test mode is enabled.
- Hive test console server:
ZoneType.TEST
- Hive sandbox console server:
ZoneType.SANDBOX
- Hive commercial console server:
ZoneType.REAL
1 2 3 |
Adiz.setZone(AdizConfiguration.ZoneType.REAL) |
1 2 3 |
Adiz.setZone(AdizConfiguration.ZoneType.REAL); |
GDPR Consent Popup Display (Europe and UK)
If your game targets Europe and the UK (EEA & UK), it is required to display a GDPR (General Data Protection Regulation) consent popup. The GDPR consent popup will only be shown if the user’s device IP address is from Europe or the UK (EEA & UK). Hive Adiz supports Google‘s UMP (User Messaging Platform) for displaying the GDPR consent popup.
After creating the GDPR message in the AdMob console, the GDPR popup will be displayed to users accessing from Europe and the UK when you initialize Hive Adiz.
Creating GDPR Message
Access the Google AdMob console to create the GDPR message. Before creating the GDPR message, refer to the GDPR message creation guide.
After creating the GDPR message, the GDPR consent popup will automatically be displayed during the initialization of Hive Adiz.
Implementing Options for GDPR Consent/Withdrawal
The GDPR consent popup should allow users to modify their consent at any time. For instance, users who initially did not consent to GDPR but wish to receive personalized ads may want to consent, or vice versa. To accommodate such scenarios, developers must implement functionality for users to either consent again or withdraw their previous consent. To implement GDPR consent/withdrawal functionality, follow these steps:
- Implement a button UI in your app to reload the GDPR consent popup window.
- When implementing the initialization of Hive Adiz, call
isPrivacyOptionsRequired()
to display the button UI above for users accessing from Europe and the UK, and not display it otherwise. If users from Europe and the UK press the button, callshowPrivacyOptionsForm
to reload the GDPR consent popup, allowing users to modify their consent for GDPR details at any time through a “Manage Options” button or similar within the app. TheshowPrivacyOptionsForm
method provided below is for illustration purposes only and can be implemented in any form desired by the developer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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) { // ... Skipped // Determine whether to display a button on the app UI to show the GDPR consent popup again var isPrivacyOptionsRequired = AdizConsentManager.isPrivacyOptionsRequired() if(isPrivacyOptionsRequired) { // Display the button in the app. (When the button is clicked, call showPrivacyOptionsForm() to display the GDPR consent popup) showGDPRConsentPopupButton() } else { // Will not display the button in the app. // Perform other desired actions within the app. } } } }) } fun showPrivacyOptionsForm(activity: Activity) { // Call the GDPR consent popup 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. } }) } } |
Setting Tag For Under the Age of Consent
Using the Tag For Under the Age of Consent (TFUA), you can configure ad requests to treat users residing in the European Economic Area (EEA), the United Kingdom, and Switzerland as subjects to limited data processing. For apps that serve children, you can set that the user is 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. The age of consent setting must be configured before executing Adiz.initialize
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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 this to true if the user is 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?) { // ... skipped } }) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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 this to true if the user is 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()) { // ... skipped } } }); } |
Setting up GDPR Test Devices
The GDPR consent popup is displayed only if the device’s IP address is from Europe or the UK. During development, you can force the GDPR consent popup to display regardless of the device IP address for testing purposes by setting up GDPR test devices. Follow the steps below to set up GDPR test devices. The following content is the same as Displaying ads on a test device.
- Initialize Hive Adiz. The purpose of this initialization is to check the test device ID, so you don’t need to create a GDPR consent message in advance.
- Find the device ID in the Logcat log output. Here’s an example message:
Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
Get the device ID (example:
33BE2250B43518CCDA7DE426D04EE231
). - Copy the device ID.
- Add
Adiz.setTestDevice(DEVICE_ID)
before executingAdiz.initialize
in the existing Hive Adiz initialization code. - Create a GDPR consent message and reinitialize Hive Adiz to ensure the GDPR consent popup appears correctly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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?) { // ... Skipped } }) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
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()) { // ... Skipped } } }); } |
Setting the Tag for Child-Directed Treatment
In accordance with the Children’s Online Privacy Protection Act (COPPA), app developers can specify whether Google should treat content as child-directed during ad requests by setting the tagForChildDirectedTreatment (TFCD). If you wish the content to be treated as directed towards children, you must call AdizConsentManager.setUserPrivacySettings
before executing Adiz.initialize
. When using Hive Adiz with the Hive SDK, the tag for child-directed treatment is automatically applied, so no additional settings are required.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import com.hive.Adiz import com.hive.adiz.AdizError import com.hive.adiz.consent.PrivacySettings import org.json.JSONObject fun initialize() { val isChildDirectedTreatmentForCOPPA = false // set true if the user 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?) { // ... skipped } }) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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; // set true if the user is a child 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()) { // ... skipped } } }); } |
Add mediation for ads
Hive Adiz allows displaying ads using AdMob mediation. To add AdMob mediation, follow the steps below.
Add AdMob mediation
Proceed with integrating the ad sources in the AdMob console. Follow the table below.
Add Adiz Adapter
Add the library dependency to your app-level build.gradle.
1 2 3 4 5 6 7 8 9 10 11 12 |
dependencies { // ... (omitted) implementation 'com.com2us.android.adiz:hive-adiz:2.0.0' // Common (must be added) implementation 'com.com2us.android.adiz:hive-adiz-adapter-applovin:2.0.1' // Add for AppLovin integration implementation 'com.com2us.android.adiz:hive-adiz-adapter-pangle:2.0.1' // Add for Pangle integration implementation 'com.com2us.android.adiz:hive-adiz-adapter-unityads:2.0.1' // Add for Unity Ads integration implementation 'com.com2us.android.adiz:hive-adiz-adapter-meta:2.0.1' // Add for Meta integration } |
When integrating with Pangle, add the following settings. If you are using Gradle 7.0 or above, add the repository
settings in the dependencyResolutionManagement
section of your project-level settings.gradle.
1 2 3 4 5 6 7 8 9 |
// Settings for Gradle 7.0 or above in settings.gradle dependencyResolutionManagement { repositories { maven { url 'https://artifact.bytedance.com/repository/pangle/' } // Add for Pangle integration } } |
If you are using Gradle version less than 7.0, add the repository
settings in the allprojects
section of your project-level build.gradle.
1 2 3 4 5 6 7 8 9 10 11 12 |
// Settings for Gradle version less than 7.0 in build.gradle allprojects { repositories { maven { url 'https://artifact.bytedance.com/repository/pangle' // Add for Pangle integration } } } |
To verify if the Adiz adapter configuration has been properly applied, run your app and check the configuration list on the Ad Inspector screen.
Initializing Hive Adiz
The initialization of Hive Adiz is the essential step before exposing any type of advertisement. When you initialize Hive Adiz, you can receive the necessary ad keys to display ads. If test mode is enabled, you will receive a test key. If you are using the Hive SDK, proceed with Adiz initialization after calling AuthV4.setup
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
Adiz.initialize(activity, 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) { //... } } } } }) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
Adiz.initialize(activity, 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); // 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") == 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) { } } } } }); |
When initializing, the JSON file received as a callback includes a list of ad keys. The format of the ad key list is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
{ "keys":[ { "mediation_id":5, "key":"ca-app-pub-3940256099942544/5354046379", "form":"rewarded_interstitial", "is_default":true }, { "mediation_id":4, "key":"ca-app-pub-3940256099942544/5224354917", "form":"rewarded", "is_default":true }, { "mediation_id":3, "key":"ca-app-pub-3940256099942544/2247696110", "form":"native", "is_default":true }, { "mediation_id":1, "key":"ca-app-pub-3940256099942544/1033173712", "form":"interstitial", "is_default":true }, { "mediation_id":2, "key":"ca-app-pub-3940256099942544/6300978111", "form":"banner", "is_default":true }, { "mediation_id":6, "key":"ca-app-pub-3940256099942544/9257395921", "form":"app_open", "is_default":true } ] } |
If you initialize in test mode, you will receive a list of test ad keys even if you have not registered an AdMob ad key in the Hive console. If you initialize in commercial mode, you will receive a list of AdMob ad keys registered in the Hive console.
Each ad format has one ad as the default ad (an ad with "is_default":true
). The first ad registered becomes the default ad for that ad format. You do not need to enter the ad key (hiveAdKey
) when creating the ad instance (initialize()
) for the default ad. To change the default ad, you must delete the existing default ad in the Hive console and re-register the ad.
Setting Up Ad Callback Listeners
You can receive callbacks based on the state changes of an ad by implementing the AdizListener
when creating each ad instance.
Name | Description | Required |
---|---|---|
onLoad() | Ad load successful | O |
onFail(error: AdizError) | Failure (you can understand the reason for failure through error.getCode() and error.getMessage() ) |
O |
onShow() | Ad display successful | O |
onClick() | Ad clicked | O |
onPaidEvent(adRevenueData: AdRevenueData) | This is a point at which a paid event is received after the ad is displayed. At this point, the ad revenue information is delivered. | O |
onClose() | Ad closed
|
X |
onRewarded(rewardItem: RewardItem) | The point at which the user receives a reward after an ad display for rewarded (rewarded , rewarded interstitial ) ads |
X |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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 } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
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
The error codes and error messages for Adiz.Initialize
and AdizListener
when onFail()
is received are as follows:
Common Codes
Number | Case | Explanation |
---|---|---|
0 | Success | Successful |
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 |
Ad Platform Error Codes
Number | Case | Explanation |
---|---|---|
-101 | NeedLoad | Ad not loaded |
-102 | NeedReload | Need to reload due to ad display time expiration |
-103 | NotEnoughInventory | Mediation response was successful, but no filled ads due to insufficient 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 handle ad request |
-108 | AlreadyLoaded | Already loaded |
-109 | CannotRequestAds | Cannot request ads |
-201 | GdprConsentError | GDPR consent error |
-202 | IsNotPrivacyOptionsRequired | No need to display or unable to display the GDPR consent popup |
Ad Exposure and Termination
To expose and terminate ads, follow these steps:
- Create ad instances from the ad class for each type of ad you want to expose. If the ad you want to expose is not a default ad, you need to enter the ad key obtained from initialization. If you do not enter the ad key (
hiveAdKey
), a default ad instance is created. - Load (
load()
) the ad you want to expose. - Expose (
show()
) the loaded ad. To re-expose the ad, you must callload()
again followed byshow()
. - To terminate the ad, call
destroy()
.
Interstitial Ads
These are full-screen ads that take up the entire screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
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) } fun requestInitAd(activity: Activity, hiveAdKey: String? = null) { 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() } } if(hiveAdKey == null) { // 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 requestLoadAd() { // Load the interstitial ad. interstitialAd?.load() } fun requestShowAd() { // Expose the interstitial ad. interstitialAd?.show() } fun requestDestroyAd() { // Remove the interstitial ad. interstitialAd?.destroy() } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
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); } public void requestInitAd(Activity activity, String hiveAdKey) { 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 } }; 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(); } private void requestLoadAd() { // Load the interstitial ad. if(interstitialAd != null) interstitialAd.load(); } private void requestShowAd() { // Expose the interstitial ad. if(interstitialAd != null) interstitialAd.show(); } private void requestDestroyAd() { // Remove the interstitial ad. if(interstitialAd != null) interstitialAd.destroy(); } } |
Banner Ads (Banner)
Banner ads expose a banner of a specific size. Banner ads do not receive the onClose()
callback. Therefore, you must call destroy()
from another location to terminate the ad.
BannerSize
follows standard banner sizes.
Size Point (Width x Height) | Description | Supported Devices | BannerSize Constant |
---|---|---|---|
320×50 | Banner | Mobile phones and tablets | BannerSize.NORMAL |
320×100 | Large Banner | Mobile phones and tablets | BannerSize.MEDIUM |
300×250 | IAB Medium Rectangle | Mobile phones and tablets | BannerSize.LARGE |
468×60 | IAB Full-Size Banner | Tablets | BannerSize.FULL |
PositionType
is either top or bottom. 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 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
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) } fun requestInitAd(activity: Activity, hiveAdKey: String? = null) { 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 } } if(hiveAdKey == null) { // 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 requestLoadAd() { // Load the banner ad. banner?.load() } fun requestShowAd() { // Expose the banner ad. banner?.show() // Set banner position // var position = PositionType.TOP // banner?.show(position) } fun requestDestroyAd() { // Remove the banner ad. banner?.destroy() } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
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); } public void requestInitAd(Activity activity, String hiveAdKey) { 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 } }; 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(); } private void requestLoadAd() { // Load the banner ad. if(banner != null) banner.load(); } private void requestShowAd() { // Expose the banner ad. if(banner != null) 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 Ads (Native)
Native ads display a specific size of the native template. Native ads are optimized for portrait screens, so it is recommended to use them in portrait games (vertical screen games). Native ads do not receive the onClose()
callback. Therefore, you must call destroy()
from another location to terminate the ad.
Currently, the templates support small
or medium
sizes.
Template | Alignment | BannerSize Constant |
---|---|---|
small size | Top / Bottom | BannerSize.NORMAL |
medium size | Center (fixed) | BannerSize.MEDIUM |
For the small
template, PositionType
is 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 selection of alignment and defaults to center alignment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
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) } fun requestInitAd(activity: Activity, hiveAdKey: String? = null) { 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 } } if(hiveAdKey == null) { // 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 requestLoadAd() { // Load the native ad. nativeAd?.load() } fun requestShowAd() { // Display the native ad. nativeAd?.show() // Set banner position // var position = PositionType.TOP // nativeAd?.show(position) } fun requestDestroyAd() { // Remove the native ad. nativeAd?.destroy() } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
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); } public void requestInitAd(Activity activity, String hiveAdKey) { 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 } }; 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(); } private void requestLoadAd() { // Load the native ad. if(nativeAd != null) nativeAd.load(); } private void requestShowAd() { // Display the native ad. if(nativeAd != null) nativeAd.show(); // Set banner position // PositionType position = PositionType.TOP; // if(nativeAd != null) nativeAd.show(position); } private void requestDestroyAd() { // Remove the native ad. if(nativeAd != null) nativeAd.destroy(); } } |
Rewarded Ads (Rewarded)
These are rewarded ads where users receive rewards for watching the ad for a certain amount of time. When the reward is successfully provided, reward item information is received through the onRewarded()
callback.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
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) } fun requestInitAd(activity: Activity, hiveAdKey: String? = null) { 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 } } if(hiveAdKey == null) { // 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 requestLoadAd() { // Load the rewarded ad. rewardedAd?.load() } fun requestShowAd() { // Display the rewarded ad. rewardedAd?.show() } fun requestDestroyAd() { // Remove the rewarded ad. rewardedAd?.destroy() } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
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); } public void requestInitAd(Activity activity, String hiveAdKey) { 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 } }; 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(); } private void requestLoadAd() { // Load the rewarded ad. if(rewardedAd != null) rewardedAd.load(); } private void requestShowAd() { // Display the rewarded ad. if(rewardedAd != null) rewardedAd.show(); } private void requestDestroyAd() { // Remove the rewarded ad. if(rewardedAd != null) rewardedAd.destroy(); } } |
Rewarded Interstitial Ads (Rewarded Interstitial)
Rewarded interstitial ads allow users to receive rewards after watching ads for a certain period. Once the reward is granted, the reward item information is received through the onRewarded()
callback.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
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) } fun requestInitAd(activity: Activity, hiveAdKey: String? = null) { 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 } } if(hiveAdKey == null) { // 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 requestLoadAd() { // Loads the rewarded interstitial ad. rewardedInterstitialAd?.load() } fun requestShowAd() { // Displays the rewarded interstitial ad. rewardedInterstitialAd?.show() } fun requestDestroyAd() { // Removes the rewarded interstitial ad. rewardedInterstitialAd?.destroy() } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
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); } public void requestInitAd(Activity activity, String hiveAdKey) { 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 } }; 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(); } private void requestLoadAd() { // Loads the rewarded interstitial ad. if(rewardedInterstitialAd != null) rewardedInterstitialAd.load(); } private void requestShowAd() { // Displays the rewarded interstitial ad. if(rewardedInterstitialAd != null) rewardedInterstitialAd.show(); } private void requestDestroyAd() { // Removes the rewarded interstitial ad. if(rewardedInterstitialAd != null) rewardedInterstitialAd.destroy(); } } |
Here’s the translated content:
App Opening Ads (AppOpen)
App opening ads display pre-loaded (load()
) ads when the app status changes from background to foreground. If show()
is called 3 hours after the ad is loaded, the ad will be automatically reloaded before being displayed. Once the ad is displayed at least once, it will not be automatically reloaded.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
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) } fun requestInitAd(activity: Activity, hiveAdKey: String? = null) { 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() } } if(hiveAdKey == null) { // 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 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?.load() } fun requestDestroyAd() { // Removes the app opening ad. appOpen?.destroy() } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
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); } public void requestInitAd(Activity activity, String hiveAdKey) { 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(); } }; 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(); } private void requestLoadAd() { // Loads the app opening ad. if(appOpen != null) appOpen.load(); } private void requestDestroyAd() { // Removes the app opening ad. if(appOpen != null) appOpen.destroy(); } } |