Huawei Ads Kit adaptation for Python / Kivy. Structurally inspired from KivMob by Michael Stott
Currently only Rewarded Ads format supported! Other formats will be added over time.
-
Just add
KuaveyAdsKit.py
to your Kivy project root. -
Download the appropriate ADS SDK from the Huawei Developers website. Like
adssdk-eclipse-3.4.37.300.zip
from that developer.huawei.com page. -
Extract the JAR files from the archive (only JAR files are needed). The following JAR files should appear in your project:
- ads-base.jar (root JAR file for the entire SDK)
- ads-reward.jar
Other JAR files are not used by the KuaveyAdsKit yet!
For convenience, put these JAR files in a separate folder in your project, for example, in the adskit
folder.
- Add to your
buildozer.spec
file links to these JARs, like:
android.add_jars = adskit/*.jar
- Import
KuaveyAdsKit
andHmsRewardAdListenerInterface
classes:
...
if platform == 'android':
from KuaveyAdsKit import KuaveyAdsKit, HmsRewardAdListenerInterface
....
- Inherit the
HmsRewardAdListenerInterface
into a new class to override the methods (if you want to track the ad showing status and perform some action):
...
class HmsRewardsHandler(HmsRewardAdListenerInterface):
def on_rewarded(self, paramReward):
# do_something()
print("Thanks for watching donation.")
def on_reward_ad_closed(self):
# do_something()
print("You didn't wait for the ad to end")
def on_reward_ad_failed_to_load(self, paramInt):
print("Error code:", paramInt)
def on_reward_ad_left_app(self):
pass
def on_reward_ad_loaded(self):
pass
def on_reward_ad_opened(self):
pass
def on_reward_ad_completed(self):
pass
def on_reward_ad_started(self):
pass
...
- Initialize the
KuaveyAdsKit
and load ads, specifying the ID and new listening interface as arguments.
...
hms_ads = KuaveyAdsKit()
hms_ads.load_rewarded_ad("testx9dtjwj8hp", HmsRewardsHandler())
...
- Show ads where needed:
...
hms_ads.show_reward_ad()
...
- Don't forget to load ads after returning to kivy activity:
...
class MyKivyApp(App):
...
def on_resume(self):
hms_ads.load_rewarded_ad("testx9dtjwj8hp", HmsRewardsHandler())
...