KivMob没有加载广告

时间:2018-09-26 05:02:27

标签: python admob kivy

下面是我从GitHub上的KivMob示例重做的“ Hello World”代码段。这些示例并没有真正的帮助,因为它们缺少适当的注释,所以我不知道发生了什么。

将此应用移植到Android时看不到任何广告。我也看不到应该如何显示广告以及在哪里显示广告的逻辑。有人可以帮我让KivMob出现在Android上吗?

from kivmob import KivMob
import kivy.utils
from kivy.app import App
from kivy.lang import Builder
from kivy.config import Config
from kivy.properties import ListProperty
from kivy.utils import platform
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.label import Label

if platform not in ('android', 'ios'):
    # Approximate dimensions of mobile phone.
    Config.set('graphics', 'resizable', '0')

__version__ = "1.0"

Builder.load_string("""
#:import kivy kivy
<KivMobDemoUI>:
    canvas.before:
        Rectangle:
            pos: self.pos
            size: self.size
    FloatLayout:
    BoxLayout:
        orientation: "vertical"
        AnchorLayout:
            CustomButton:
                text: "Toggle Banner"
                size_hint: 0.8, 0.2
                on_release: app.toggle_banner()
<CustomButton>:
    canvas.before:
        Color:
            rgba: self.box_color
        RoundedRectangle:
            pos: self.pos
            size: self.size
    color: (1, 1, 1, 1)
    bold: True
    text_size: self.width, None
    height: self.texture_size[1]+size_hint_y: None
    text_size: self.width, None
    height: self.texture_size[1] + sp(20)
    halign: 'center'
    valign: 'middle'
""")


class KivMobDemoUI(FloatLayout):
    pass


class CustomButton(ButtonBehavior, Label):

    box_color = ListProperty(kivy.utils.get_color_from_hex("56b669"))
    prv_color = ListProperty(kivy.utils.get_color_from_hex("56b669"))

    def __init__(self, **kwargs):
        super(CustomButton, self).__init__(**kwargs)
        self.always_release = True

    def on_press(self):
        self.prv_color = self.box_color
        self.box_color = (0,0,0,1)

    def on_release(self):
        self.box_color = self.prv_color


class KivMobDemo(App):

    def build(self):
        APP_ID = "ca-app-pub-ENTER#"
        BANNER_ID = "ca-app-pub-ENTER#"
        TEST_DEVICE_ID = "ca-app-pub-ENTER#"

        self.ads = KivMob(APP_ID)
        self.ads.add_test_device(TEST_DEVICE_ID)
        self.ads.new_banner({"unitID": BANNER_ID})
        self.ads.show_banner()
        self.ads.request_banner()
        self.toggled = False
        return KivMobDemoUI()

    def on_pause(self):
        return True

    def on_resume(self):
        return True

    def toggle_banner(self):
        if not self.toggled:
            self.ads.show_banner()
        else:
            self.ads.hide_banner()
        self.toggled = not self.toggled

if __name__ == "__main__":
    KivMobDemo().run()

1 个答案:

答案 0 :(得分:0)

您必须在buildozer.spec文件中添加一些注释:

requirements = kivy, android, jnius, kivmob
...
android.permissions = INTERNET, ACCESS_NETWORK_STATE
android.api = 27
android.minapi = 21
android.sdk = 24
android.ndk = 17b
android.gradle_dependencies = 'com.google.firebase:firebase-ads:10.2.0'
p4a.branch = master
android.meta_data = com.google.android.gms.ads.APPLICATION_ID=ca-app-pub-3940256099942544~3347511713