Tutorial
Installation
KivMob is available for download from the Python Package Index using pip:
$ pip3 install https://github.com/MichaelStott/KivMob/archive/refs/heads/master.zip
Alternatively, you can install it from the source via setup.py
$ python3 setup.py install --user
Android Configuration
Modify buildozer.spec as such:
requirements = python3, kivy, android, jnius, https://github.com/MichaelStott/KivMob/archive/refs/heads/master.zip
...
android.permissions = INTERNET, ACCESS_NETWORK_STATE
android.api = 33
android.minapi = 21
android.sdk = 33
android.ndk = 25b
android.gradle_dependencies = com.google.firebase:firebase-ads:23.6.0
android.enable_androidx = True
p4a.branch = master
# For test ads, use application ID ca-app-pub-3940256099942544~3347511713
android.meta_data = com.google.android.gms.ads.APPLICATION_ID=ADMOB_APP_ID_HERE
Interstitials
Interstitial ads are full-screen ads that cover the entire app until dismissed by the user.
from kivmob import KivMob, TestIds
from kivy.app import App
from kivy.uix.button import Button
class InterstitialTest(App):
""" Display an interstitial ad on button release.
"""
def build(self):
self.ads = KivMob(TestIds.APP)
self.ads.new_interstitial(TestIds.INTERSTITIAL)
self.ads.request_interstitial()
return Button(text='Show Interstitial',
on_release=lambda a:self.ads.show_interstitial())
def on_resume(self):
self.ads.request_interstitial()
if __name__ == "__main__":
InterstitialTest().run()
Rewarded Video
Ads the user may view in exchange for in-app rewards. Callback functionality can be handled with a class implementing RewardedListenerInterface.
from kivmob import KivMob, TestIds, RewardedListenerInterface
from kivy.app import App
from kivy.uix.button import Button
class RewardedVideoTest(App):
""" Display a rewarded video ad on button release.
"""
def build(self):
self.ads = KivMob(TestIds.APP)
self.ads.load_rewarded_ad(TestIds.REWARDED_VIDEO)
# Add any callback functionality to this class.
self.ads.set_rewarded_ad_listener(RewardedListenerInterface())
return Button(text='Show Rewarded Ad',
on_release=lambda a:self.ads.show_rewarded_ad())
def on_resume(self):
self.ads.load_rewarded_ad(TestIds.REWARDED_VIDEO)
if __name__ == "__main__":
RewardedVideoTest().run()