Wrapper for Huawei Ads Kit. Based on Huawei Ads Kit v13.4.37.300 (28 December 2020). Github link.
Banner, Interstitial and Reward Ads.
Info about HUAWEI Ads Publisher Service.
This library is for Huawei phones only, as all Huawei phones already have HMS Core app installed. You may want to use this library for publishing your app on Huawei's AppGallery. Devices without HMS Core app will not show any ads.
For testing on other devices, you need to to download and install HMS Core APK on your device. You will find link in Main activity in example app attached to this post.
Guide how to add App and Ad units.
You should check all activities and Starter service in example app. Please read the commented text, you will find these very important notes.
There are some important things you need to do before publishing your app on AppGallery.
Consent form is not production ready, you need to change privacy and consent text. Everything is described in comments in example app.
Consent form is HTML file. You can edit file, also you can make multiple files with different languages, etc.
For HuaweiAdsKitRequestOptions check official documentation.
IMPORTANT:
to get production ads running, you need to use (as advised from Huawei support):
Set last three parameters to:
In my test only these settings return real ads, any other setting do not show ads with error NO FILL. I'm using these settings for Banner and Interstitial ads.
You can try other options.
Download library zip file from this link and extract archive to Additional Libraries folder.
What's new:
v1.30:
v1.21:
v1.20:
v1.10:
v1.00:
Banner, Interstitial and Reward Ads.
Info about HUAWEI Ads Publisher Service.
HuaweiAdsKit
Author: Author: Huawei - B4a Wrapper: Pendrush
Version: 1.30
- HuaweiAdsKit
- Events:
- AdClicked
- AdClosed
- AdFailed (Error As String)
- AdLeave
- AdLoaded
- AdOpened
- Fields:
- BANNER_SIZE_160_600 As Object
Banner - 160x600, you need to set view width to 160dip and height to 600dip- BANNER_SIZE_300_250 As Object
Banner - 300x250, you need to set view width to 300dip and height to 250dip- BANNER_SIZE_320_100 As Object
Banner - 320x100, you need to set view width to 320dip and height to 100dip- BANNER_SIZE_320_50 As Object
Banner - 320x50, you need to set view width to 320dip and height to 50dip- BANNER_SIZE_360_144 As Object
Banner - 360x144, you need to set view width to 360dip and height to 144dip- BANNER_SIZE_360_57 As Object
Banner - 360x57, you need to set view width to 360dip and height to 57dip- BANNER_SIZE_468_60 As Object
Banner - 468x60, you need to set view width to 468dip and height to 60dip- BANNER_SIZE_728_90 As Object
Banner - 728x90, you need to set view width to 728dip and height to 90dip- BANNER_SIZE_SMART As Object
Banner - Smart, you need to set view width to 100%x and height to 32dip or 50dip or 90dip- Functions:
- BringToFront
- Initialize (EventName As String, AdId As String, AdSize As com.huawei.hms.ads.BannerAdSize)
Initialize banner ad
HuaweiAdsKitBanner1.Initialize("HuaweiAdsKitBanner1", "testw6vs28auh3", HuaweiAdsKitBanner1.BANNER_SIZE_320_50)
Activity.AddView(HuaweiAdsKitBanner1, 50%x-160dip, 0, 320dip, 50dip)- Invalidate
- Invalidate2 (arg0 As android.graphics.Rect)
- Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
- IsInitialized As Boolean
- LoadAd (BannerRefresh As Long, Personalized As Boolean, AdContentClassification As String, TagForUnderAgeOfPromise As Int, TagForChildProtection As Int)
Load banner ad
BannerRefresh - refresh time for banner ad in seconds
Personalized - if is True personlized ad will be loaded, False for non personlized
AdContentClassification - Sets the maximum ad content rating for the ad requests of your app. The ads obtained using this method have a content rating at or below the specified one.
TagForUnderAgeOfPromise - Sets the tag for users under the age of consent, to comply with the General Data Protection Regulation (GDPR). Ad requests with this tag enabled will be unable to obtain personalized ads.
TagForChildProtection - Sets the tag for child-directed content, to comply with the Children's Online Privacy Protection Act (COPPA).
HuaweiAdsKitBanner1.LoadAd(30, True, RequestOptions1.AD_CONTENT_CLASSIFICATION_W, RequestOptions1.TAG_FOR_UNDER_AGE_PROMISE_TRUE, RequestOptions1.TAG_FOR_CHILD_PROTECTION_TRUE)- Pause
Pause banner ad.
Should be called from Activity_Pause- RemoveView
- RequestFocus As Boolean
- Resume
Resume banner ad.
Should be called from Activity_Resume- SendToBack
- SetBackgroundImage (arg0 As android.graphics.Bitmap) As BitmapDrawable
- SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
- SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
- SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
- SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
- Properties:
- Background As android.graphics.drawable.Drawable
- Color As Int [write only]
- Enabled As Boolean
- Height As Int
- Left As Int
- Padding As Int()
- Parent As Object [read only]
- Tag As Object
- Top As Int
- Visible As Boolean
- Width As Int
- HuaweiAdsKitConsent
- Events:
- ConsentStatusFailed (Error As String)
- IsNeedConsent (AdProviders As Map)
- NeedConsent (ConsentStatus As Int)
- UpdateConsentStatus (ConsentStatus As Int)
- Fields:
- CONSENT_STATUS_NON_PERSONALIZED As Object
- CONSENT_STATUS_PERSONALIZED As Object
- CONSENT_STATUS_UNKNOWN As Object
- DEBUG_DISABLED As Object
- DEBUG_NEED_CONSENT As Object
- DEBUG_NOT_NEED_CONSENT As Object
- Functions:
- CheckConsentStatus (DebugMode As Boolean, DebugConsent As com.huawei.hms.ads.consent.constant.DebugNeedConsent, DebugConsentStatus As com.huawei.hms.ads.consent.constant.ConsentStatus)
Check consent status.
DebugMode - if is True second and third parameters will be applied, if it is False, second and third parameters will be ignored.
HuaweiAdsKitConsent1.CheckConsentStatus(True, HuaweiAdsKitConsent1.DEBUG_NEED_CONSENT, HuaweiAdsKitConsent1.CONSENT_STATUS_UNKNOWN)- Initialize (EventName As String)
Initialize HuaweiAdsConsent
HuaweiAdsKitConsent1.Initialize("HuaweiAdsKitConsent1")- IsInitialized As Boolean
- SetConsentStatus (consentStatus As com.huawei.hms.ads.consent.constant.ConsentStatus)
Set consent status.
HuaweiAdsKitConsent1.SetConsentStatus(HuaweiAdsKitConsent1.CONSENT_STATUS_PERSONALIZED)- HuaweiAdsKitInterstitial
- Events:
- AdClicked
- AdClosed
- AdFailed (Error As String)
- AdImpression
- AdLeave
- AdLoaded
- AdOpened
- Functions:
- Initialize (EventName As String, AdId As String)
Initialize interstitial ad
HuaweiAdsKitInterstitial1.Initialize("HuaweiAdsKitInterstitial1", "teste9ih9j0rc3")
Test AdId for Image Ad = teste9ih9j0rc3
Test AdId for Video Ad = testb4znbuh3n2- IsInitialized As Boolean
- IsLoaded As Boolean
Check is interstitial ad loaded- LoadAd (Personalized As Boolean, AdContentClassification As String, TagForUnderAgeOfPromise As Int, TagForChildProtection As Int)
Load interstitial ad
Personalized - if is True personlized ad will be loaded, False for non personlized
AdContentClassification - Sets the maximum ad content rating for the ad requests of your app. The ads obtained using this method have a content rating at or below the specified one.
TagForUnderAgeOfPromise - Sets the tag for users under the age of consent, to comply with the General Data Protection Regulation (GDPR). Ad requests with this tag enabled will be unable to obtain personalized ads.
TagForChildProtection - Sets the tag for child-directed content, to comply with the Children's Online Privacy Protection Act (COPPA).
HuaweiAdsKitInterstitial1.LoadAd(True, RequestOptions1.AD_CONTENT_CLASSIFICATION_W, RequestOptions1.TAG_FOR_UNDER_AGE_PROMISE_TRUE, RequestOptions1.TAG_FOR_CHILD_PROTECTION_TRUE)- ShowAd
Show interstitial ad- HuaweiAdsKitRequestOptions
- Fields:
- AD_CONTENT_CLASSIFICATION_A As String
Sets the maximum ad content rating for the ad requests of your app. The ads obtained using this method have a content rating at or below the specified one.
AD_CONTENT_CLASSIFICATION_A: content suitable only for adults.- AD_CONTENT_CLASSIFICATION_J As String
Sets the maximum ad content rating for the ad requests of your app. The ads obtained using this method have a content rating at or below the specified one.
AD_CONTENT_CLASSIFICATION_J: content suitable for junior and older audiences.- AD_CONTENT_CLASSIFICATION_PI As String
Sets the maximum ad content rating for the ad requests of your app. The ads obtained using this method have a content rating at or below the specified one.
AD_CONTENT_CLASSIFICATION_PI: content suitable for audiences with parental guidance.- AD_CONTENT_CLASSIFICATION_UNKOWN As String
Sets the maximum ad content rating for the ad requests of your app. The ads obtained using this method have a content rating at or below the specified one.
AD_CONTENT_CLASSIFICATION_UNKOWN: Unknown- AD_CONTENT_CLASSIFICATION_W As String
Sets the maximum ad content rating for the ad requests of your app. The ads obtained using this method have a content rating at or below the specified one.
AD_CONTENT_CLASSIFICATION_W: content suitable for widespread audiences.- TAG_FOR_CHILD_PROTECTION_FALSE As Int
Sets the tag for child-directed content, to comply with the Children's Online Privacy Protection Act (COPPA).
TAG_FOR_CHILD_PROTECTION_FALSE: You do not want your ad content to be COPPA-compliant.- TAG_FOR_CHILD_PROTECTION_TRUE As Int
Sets the tag for child-directed content, to comply with the Children's Online Privacy Protection Act (COPPA).
TAG_FOR_CHILD_PROTECTION_TRUE: You want your ad content to be COPPA-compliant (interest-based ads and remarketing ads will be disabled for the ad request).- TAG_FOR_CHILD_PROTECTION_UNSPECIFIED As Int
Sets the tag for child-directed content, to comply with the Children's Online Privacy Protection Act (COPPA).
TAG_FOR_CHILD_PROTECTION_UNSPECIFIED: You do not want to indicate whether your ad content needs to be COPPA-compliant.- TAG_FOR_UNDER_AGE_PROMISE_FALSE As Int
Sets the tag for users under the age of consent, to comply with the General Data Protection Regulation (GDPR). Ad requests with this tag enabled will be unable to obtain personalized ads.
UNDER_AGE_PROMISE_FALSE: You do not want the ad content to meet the ad standard for users under the age of consent.- TAG_FOR_UNDER_AGE_PROMISE_TRUE As Int
Sets the tag for users under the age of consent, to comply with the General Data Protection Regulation (GDPR). Ad requests with this tag enabled will be unable to obtain personalized ads.
UNDER_AGE_PROMISE_TRUE: You want the ad content to meet the ad standard for users under the age of consent.- TAG_FOR_UNDER_AGE_PROMISE_UNSPECIFIED As Int
Sets the tag for users under the age of consent, to comply with the General Data Protection Regulation (GDPR). Ad requests with this tag enabled will be unable to obtain personalized ads.
UNDER_AGE_PROMISE_UNSPECIFIED: You have not specified whether the ad content should meet the ad standard for users under the age of consent- Functions:
- Initialize
Initialize RequestOptions- HuaweiAdsKitReward
- Events:
- RewardAdClosed
- RewardAdFailedToLoad (Error As String)
- RewardAdFailedToShow (Error As String)
- RewardAdOpened
- Rewarded (RewardName As String, RewardAmount As Int)
- RewardedLoaded
- Functions:
- Initialize (EventName As String, AdId As String)
Initialize reward ad- IsInitialized As Boolean
- IsLoaded As Boolean
Check is reward ad loaded- LoadAd (Personalized As Boolean, AdContentClassification As String, TagForUnderAgeOfPromise As Int, TagForChildProtection As Int)
Load reward ad
Personalized - if is True personlized ad will be loaded, False for non personlized
AdContentClassification - Sets the maximum ad content rating for the ad requests of your app. The ads obtained using this method have a content rating at or below the specified one.
TagForUnderAgeOfPromise - Sets the tag for users under the age of consent, to comply with the General Data Protection Regulation (GDPR). Ad requests with this tag enabled will be unable to obtain personalized ads.
TagForChildProtection - Sets the tag for child-directed content, to comply with the Children's Online Privacy Protection Act (COPPA).
HuaweiAdsKitReward1.LoadAd(True, RequestOptions1.AD_CONTENT_CLASSIFICATION_W, RequestOptions1.TAG_FOR_UNDER_AGE_PROMISE_TRUE, RequestOptions1.TAG_FOR_CHILD_PROTECTION_TRUE)- ShowAd
Show reward ad- HuaweiAdsKitSDK
- Functions:
- Initialize
Initialize HuaweiAdsSDK
It should be initialized only once in Starter Service on Service_Create
HuaweiAdsSDK1.Initialize- SetVideoMuted (Muted As Boolean)
Sets whether to mute videos.- SetVideoVolume (Volume As Float)
Sets the video volume. You can use any value between 0.0 - 1.0
0.0 = set volume to 0%
1.0 = set volume to 100%
This library is for Huawei phones only, as all Huawei phones already have HMS Core app installed. You may want to use this library for publishing your app on Huawei's AppGallery. Devices without HMS Core app will not show any ads.
For testing on other devices, you need to to download and install HMS Core APK on your device. You will find link in Main activity in example app attached to this post.
Guide how to add App and Ad units.
You should check all activities and Starter service in example app. Please read the commented text, you will find these very important notes.
There are some important things you need to do before publishing your app on AppGallery.
Consent form is not production ready, you need to change privacy and consent text. Everything is described in comments in example app.
Consent form is HTML file. You can edit file, also you can make multiple files with different languages, etc.
For HuaweiAdsKitRequestOptions check official documentation.
IMPORTANT:
to get production ads running, you need to use (as advised from Huawei support):
B4X:
HuaweiBanner1.LoadAd(30, True/False, HuaweiRequestOptions1.AD_CONTENT_CLASSIFICATION_A, HuaweiRequestOptions1.TAG_FOR_UNDER_AGE_PROMISE_UNSPECIFIED, HuaweiRequestOptions1.TAG_FOR_CHILD_PROTECTION_UNSPECIFIED)
B4X:
HuaweiRequestOptions1.AD_CONTENT_CLASSIFICATION_A
HuaweiRequestOptions1.TAG_FOR_UNDER_AGE_PROMISE_UNSPECIFIED
HuaweiRequestOptions1.TAG_FOR_CHILD_PROTECTION_UNSPECIFIED
You can try other options.
Download library zip file from this link and extract archive to Additional Libraries folder.
What's new:
v1.30:
- Update libraries to newer version
- Two new methods for SDK: HuaweiAdsSDK.SetVideoVolume and HuaweiAdsSDK.SetVideoMuted
v1.21:
- Pause/Resume for banner
v1.20:
- Smart banner
v1.10:
- Reward Ads
- Update for example app
v1.00:
- Consent (consent.html) file - two new links will expose Huawei devices specific intents.
- Support for COPPA and GDPR in LoadAd method.
- HuaweiAdsKitSDK.Initialize is in Starter Service not in Main activity.
- HuaweiAdsKitRequestOptions - Constants for COPPA and GDPR, check official documentation.
- Two new events for InterstitialAd.
- Manifest update, as described on this link.
- Example app is also updated.
Attachments
Last edited: