Huawei Ads Kit

Pendrush

Well-Known Member
Licensed User
Longtime User
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):
B4X:
HuaweiBanner1.LoadAd(30, True/False, HuaweiRequestOptions1.AD_CONTENT_CLASSIFICATION_A, HuaweiRequestOptions1.TAG_FOR_UNDER_AGE_PROMISE_UNSPECIFIED, HuaweiRequestOptions1.TAG_FOR_CHILD_PROTECTION_UNSPECIFIED)
Set last three parameters to:
B4X:
HuaweiRequestOptions1.AD_CONTENT_CLASSIFICATION_A
HuaweiRequestOptions1.TAG_FOR_UNDER_AGE_PROMISE_UNSPECIFIED
HuaweiRequestOptions1.TAG_FOR_CHILD_PROTECTION_UNSPECIFIED
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:
  • Update libraries to newer version
v1.22:
  • 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

  • HuaweiAdsKitExample.zip
    16.6 KB · Views: 318
Last edited:

hl88

Member
Hi, I'm new to B4A. I was approve to monetize on Huawei's phone yesterday,
Where is the section I can obtain my own ad unit ID? Do I need to sign my app in order to obtain "SHA-256 certificate fingerprint" number from Android-maginfest.xml? Sorry for noob question
Thank you

 

Pendrush

Well-Known Member
Licensed User
Longtime User
You can get SHA256 with this java command
B4X:
keytool -list -v -keystore <keystore-file>
or from Tools -> Private Sign Key in B4A

Also read this guide:
 

hl88

Member
I copy paste my Ad unit Id to project, real ad is not show



Where to paste my App ID? I uploaded dummyapp.apk to AppgalleryConnect>Draft. Does its signed key need to matched with SHA-256 fingerprint I asked earlier?
 

Pendrush

Well-Known Member
Licensed User
Longtime User
Please re-read post #1 and documentation linked in post #1.
Also pay attention on tool-tip when you type code. Every method is documented in tool-tip with example code.
 

hl88

Member
Release the app and real ad will show (step 9) with only ad unit-id, no need app-id in manifest like admob?
 

Almora

Active Member
Licensed User
Longtime User
The sample application works fine on my HMS installed device. showing ads.
When I integrate the app into my app in app gallery, it doesn't show ads.

error log..

NeedConsent - we will show Consent dialog
Load Personalized Ad
Banner AdFailed: ErrorCode: 3
Interstitial AdFailed: ErrorCode: 3

huawei document
public const int NoAd
The ad request is sent successfully. However, no ad is returned due to a lack of ad resources.

Constant value: 3

huawei advertising service may differ depending on the country
 

Pendrush

Well-Known Member
Licensed User
Longtime User
Did you load banner like this?
B4X:
HuaweiBanner1.LoadAd(30, True/False, HuaweiRequestOptions1.AD_CONTENT_CLASSIFICATION_A, HuaweiRequestOptions1.TAG_FOR_UNDER_AGE_PROMISE_UNSPECIFIED, HuaweiRequestOptions1.TAG_FOR_CHILD_PROTECTION_UNSPECIFIED)
- You app (any version) MUST be published on AppGallery.
- SHA256 must be the same on their site (you need to submit it) as in your keystore file.
 

Almora

Active Member
Licensed User
Longtime User

True/False
I've tried
The application is online at the app gallery.
I added the SHA256 in the app on the developer page but ....????????(images)
 

Attachments

  • SharedScreens1hot.jpg
    63.8 KB · Views: 272
  • SharedScreenshot.jpg
    101.5 KB · Views: 270

Pendrush

Well-Known Member
Licensed User
Longtime User
You should try to publish app and check ads impressions. Maybe there is no ads for you.
 

Almora

Active Member
Licensed User
Longtime User
edit..
I added a only banner ad and it shows ads...
 
Last edited:

Pendrush

Well-Known Member
Licensed User
Longtime User
Follow instructions in post #1 and everything will work. I'm using this library in production last few months.
 

skaliwag

Member
Licensed User
Longtime User
It looks like something has changed in the latest HMS Core.
With version 5.1.0.309 all ads on a non-Huawei device are now returning ErrorCode : 0
Have Huawei stopped serving ads to non-Huawei devices?
I get the same results with the Huawei Android Studio Java example.
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…