MichaelStott / KivMob

AdMob support for Kivy
MIT License
143 stars 38 forks source link

Importing KivMob twice #121

Closed pihash252 closed 1 year ago

pihash252 commented 1 year ago

I have a Card in the main.kv file on pressing which a popup window opens with FileChooserListView. The code for the instructions inside that popup window are written in a separate Python file. Now there is a 'Submit' button inside that popup window which on pressing, after selecting a file, starts to process that file. I want to show an interstitial ad after this 'Submit' button is pressed as it seems like an apt place to show since the user will be waiting for the file to process anyway.

So far I've been able to achieve it only by importing KivMob and doing the usual. Still, since in the main.py file I've already imported the KivMob once in order to show ads while traversing other screens, I wanted to know if it'll be wrong to import it in that other Python file again. Like will Admob in any way penalize this?

Otherwise, kindly tell me another way to achieve the same.

diogokravetz commented 1 year ago

Hello, about importing Kivmob more than once, I believe that it will not generate any type of penalty and the strategy of displaying the interstitial while the user waits for a file to load is also super valid.

pihash252 commented 1 year ago

All right. Thank you

pihash252 commented 1 year ago

Also, I'm getting this in my log:

12-28 20:44:14.503 3739 3739 I python : File "/content/.buildozer/android/app/kivmob.py", line 248, in new_interstitial 12-28 20:44:14.503 3739 3739 I python : File "jnius/jnius_export_class.pxi", line 885, in jnius.jnius.JavaMethod.call 12-28 20:44:14.503 3739 3739 I python : File "jnius/jnius_export_class.pxi", line 982, in jnius.jnius.JavaMethod.call_method 12-28 20:44:14.504 3739 3739 I python : File "jnius/jnius_utils.pxi", line 91, in jnius.jnius.check_exception 12-28 20:44:14.504 3739 3739 I python : jnius.jnius.JavaException: JVM exception occurred: The ad unit ID can only be set once on InterstitialAd

Is that going to be a problem? If yes, how to deal with it?

diogokravetz commented 1 year ago

I get it, thanks for complementary, probably the google play console will identify this as a failure, so ideally it should be fixed

diogokravetz commented 1 year ago

ok, to better understand why this problem is happening I need to know if the ad unit ID is being mentioned in more than one python file.

diogokravetz commented 1 year ago

if so the only thing I could think of to solve the problem would be to change the structure of the app so that the implementation code of the interstitial ad is only in the main python file regardless of how many times it is called

diogokravetz commented 1 year ago

remember that according to google admob policies you cannot display more than one Interstitial Banner for every two user actions.

pihash252 commented 1 year ago

All right. By the way, this is my code for the interstitial ads. Am I doing it right especially with the placing of Ad unit ID? Also, the unitID is going to be different for banner and interstitial ads, right?

class MainScreen(Screen):
    ads = KivMob("ca-app-pub-1242880xxxxx~xxxxx")
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.ads.new_interstitial("ca-app-pub-1242880xxxxx/xxxxx")

    def on_pre_enter(self, *args):
        self.ads.request_interstitial()    # Intersitial ads is loaded in memory

    def on_pre_leave(self, *args):
        self.ads.request_interstitial()      # reloading ad again .

    def Show(self):
        Clock.schedule_once(lambda a:self.ads.show_interstitial(), 3)
diogokravetz commented 1 year ago

Correct, when you implement a new ad unit in your app, you'll reference the ad unit ID to tell ad networks where to send ads when they're requested, each different ad unit that you register there in admob will have a different identifier .

diogokravetz commented 1 year ago

Apparently your implementation code is correct.

pihash252 commented 1 year ago

All right. Thanks