'kivmob doesn't show ads in android app python kivy
I try to add ads in my app. I added in my buildozer.spec:
android.permissions = INTERNET, ACCESS_NETWORK_STATE
requirements = python3,kivy, jnius, kivmob
android.api = 28
android.minapi = 21
android.sdk = 24
android.ndk = 19b
android.gradle_dependencies = 'com.google.firebase:firebase-ads:10.2.0'
p4a.branch = master
android.meta_data = com.google.android.gms.ads.APPLICATION_ID=#here id of my app
I have code:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivmob import KivMob
class TestApp(App):
def build(self):
try:
fl = FloatLayout()
self.ads = KivMob('')#here my app
self.ads.add_test_device(here my id)
self.ads.new_banner('', top_pos=True)#here my banner
self.ads.request_banner()
self.ads.show_banner()
except Exception as error:
fl.add_widget(Label(text=str(error), font_size=(30)))
return fl
def on_resume(self):
self.ads.request_banner()
if __name__ == '__main__':
TestApp().run()
when I start this app, I see black screen and nothing else. I expected banner. How to fix it? I hope you help me
UPDATE:
if I use TestIds.APP
and TestIds.BANNER
it works and shows ad. Why does it happen? How to use real ad banner?
Solution 1:[1]
So firstly add android in requirements in buildozer.spec. android.api = 28
Yes using TestIds provide ads to be displayed on any device because they are sample ads by google.
But when you are using your own ad units you create from admob account. You have to provide your test device id in your code in order to recognise google that you are testing your own ads.
Use self.ads.add_test_device(YOUR_DEVICE_ID) in your build method.
And where did you get your device ID Well you have to find your device id in logcat output.
Hope it helps.
Solution 2:[2]
Kivmob is importing jnius in the process. There for it has to be included in the spec file requirements(you have done it). But you have to use pyjnius instead of jnius in the requiremnts. This might help you. But kivmob is also using android module. I don't know how to put that into requirements. So there might be some issues.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Abhay Gupta |
Solution 2 | super sonic |