Skip to content Skip to sidebar Skip to footer

Admob Rewarded Video Ads On Kivy - Java. Android

I'm trying to display google admob rewarded videos on my first game but I can't seem to make it work. This is what I have so far, I don't know Java so this is a very difficult for

Solution 1:

You're thinking in right direction but to make it work you need RewardedVideoAdListener. You can create it using PythonJavaClass and java methods from PyJnius like that:

from jnius import PythonJavaClass, java_method

from kivy.logger import Logger

from functools import partial

classRewardedVideoAdListener(PythonJavaClass):

    __javacontext__ = 'app'
    __javainterfaces__ = ["com.google.android.gms.ads.reward.RewardedVideoAdListener"]

    __INFO = True    @java_method('()V')defonRewardedVideoAdLeftApplication(self):
        if self.__INFO:
            Logger.info("AdMob: onRewardedVideoAdLeftApplication")

    @java_method('()V')defonRewardedVideoAdClosed(self):
        if self.__INFO:
            Logger.info("AdMob: onRewardedVideoAdClosed")

    @java_method('(I)V')defonRewardedVideoAdFailedToLoad(self, errorCode):
        if self.__INFO:
            Logger.info("AdMob: onRewardedVideoAdFailedToLoad, errorCode is "+str(errorCode))

    @java_method('()V')defonRewardedVideoAdLoaded(self):
        if self.__INFO:
            Logger.info("AdMob: onRewardedVideoAdLoaded")

    @java_method('()V')defonRewardedVideoAdOpened(self):
        if self.__INFO:
            Logger.info("AdMob: onRewardedVideoAdOpened")

    @java_method('(Lcom/google/android/gms/ads/reward/RewardItem;)V')defonRewarded(self, reward):
        if self.__INFO:
            Logger.info("AdMob: onRewarded, type is "+str(reward.getType())+", amount is "+str(reward.getAmount()))

    @java_method('()V')defonRewardedVideoStarted(self):
        if self.__INFO:
            Logger.info("AdMob: onRewardedVideoStarted")

Of course, you can add some handlers to this methods, for example:

from kivy.clock import Clock
from functools import partial

@java_method('(Lcom/google/android/gms/ads/reward/RewardItem;)V')defonRewarded(self, reward):
    if self.__INFO:
        Logger.info("AdMob: onRewarded, type is "+str(reward.getType())+", amount is "+str(reward.getAmount()))
    self.__rewarded = True
    Clock.schedule_once(partial(on_reward, reward.getType(), reward.getAmount()))

And you have to use this listener in your setRewardedVideoAdListener method:

mRewardedVideoAdListener = RewardedVideoAdListener()
mRewardedVideoAd.setRewardedVideoAdListener(mRewardedVideoAdListener)

Post a Comment for "Admob Rewarded Video Ads On Kivy - Java. Android"