Skip to main content

A Way To Monetize Your Kivy Game

While I am building my game, I look for a way to monetize it. This will be my first game, so it is also the first to attempt earning money with an App. I am also not familiar to monetization companies.

So, I have done a search to find an appropriate ads network which can be easily integrated with kivy. The first and only company who provides a sdk for kivy is RevMob. I integrated RevMob sdk and tested it. Unfortunately, it doesn't have a good performance and FullScreen Ads crashes. Just links will work. Therefore, RevMob option is not really preferable since ads need to be visually effective.

You can also integrate android sdk of any ads network by using pyjnius. In this post, I will show how to use Adbuddiz sdk with kivy.
First, you need to create an account at AdBuddiz and associate your application with this account. You will need 'Publisher Key' in info window of the app.

As next step, download AdBuddiz sdk and place the .jar file under libs/ directory of the project.

Here is an example code of AdBuddiz integration:

from kivy.app import App
from jnius import autoclass
from kivy.utils import platform

platform = platform()

if platform=="android":
    PythonActivity=autoclass("org.renpy.android.PythonActivity")
    AdBuddiz=autoclass("com.purplebrain.adbuddiz.sdk.AdBuddiz")

class AdsNetwork():
    def __init__(self):
        if platform=="android":
            AdBuddiz.setPublisherKey("Publisher Key");      #pass publisher key of your app as string
            AdBuddiz.setTestModeActive();                   #for testing purposes, use this command
            AdBuddiz.cacheAds(PythonActivity.mActivity);    #this will cache the ads
    def show_ads(self):
        if platform == 'android':
            AdBuddiz.showAd(PythonActivity.mActivity)   #show a popup ad

class MyGame(App):
    def build(self):
        self._adv = AdsNetwork()
        return Button(text="Show ads", on_release=self._adv.show_ads())

if __name__=="__main__":
    MyGame().run()
Some small configuration is necessary to show ads. Firstly, adnetwork uses some sources whose permissions need to be listed in AndroidManifest.xml file. To achieve it, open your buildozer.spec file and make sure following lines exist:

android.permissions = INTERNET,ACCESS_WIFI_STATE,ACCESS_NETWORK_STATE
In order buildozer to add your jar to the apk, you explicitly define it in buildozer.spec too:

android.add_jars = %(source.dir)s/libs/*.jar
It is almost done. In AdBuddiz side, it needs its activity definition to exist in AndroidManifest.xml file. For this purpose, add following line into AndroidManifest.tmpl.xml file under .buildozer/ directory:

<activity android:name="com.purplebrain.adbuddiz.sdk.AdBuddizActivity" 
                 android:theme="@android:style/Theme.Translucent" />
Your code is ready to show ads now.

 P.S. The work is originated from this wiki page of kivy.

Comments

  1. i tried the tutorial but on button release nothing happens, should i see something peticular? in the android manifest should the line pe indented or top level?

    ReplyDelete
    Replies
    1. If the test mode is active, you should see the popup app. Activity definition may be done right after python activity, under same xml tag. But this edit must be done in template AndroidManifest.xml file of buildozer. If these are done and nothing happens, logcat may be helpful, becuase in an error case adbuddiz sdk dumps related logs.

      Delete
    2. Wll try again tomorow to configure again , tried revmob as well in the mean time but to me it seems that fulscreens don`t even initialize, sadly the sdk version for kivy is 0.2, so they`re probably didn`t do any more work on it. Too bad!!

      Delete
  2. Can you tell me where excatly I should put the code in AndroidManifest.tmpl.xml

    ReplyDelete
    Replies
    1. Under application tag,you will place activity tag which will be for AdBuddizActivity, just like PythonActivity.

      Delete
  3. Doesn't look like this works anymore :c

    ReplyDelete

Post a Comment

Popular posts from this blog

Integration of MuPDF Project as a Library into an Android Studio Project

I have needed to use MuPDF library in my android project. After some research, I have seen that there are many integration tutorials but, but integrated projects are developed on Eclipse. For projects on AndroidStudio+Gradle, there is no example. I mean there is no specific example which exactly refers to this issue. So, after achieving my goal, I want to share the steps publicly so that it can be reused by others.

Encoding multi-dimensional value into 1-D with preserving closeness

After a very long time, this will be my first post. I hope that it will not be the last, and the rest will come. For a project about taxi trajectory prediction, I have applied k-NN algorithm on coordinate sequence of taxi trips. Did I have promising results? Well, it is arguable, but I have discovered some good techniques. One of them is Z-order curve (Figure 1). Figure 1: Four levels of Z-ordering (taken from Wikipedia  page) I was looking for a technique to decrease dimensionality of 2-D coordinate representation (lat-lon) into 1-D . But on this 1-D value, I would like to apply k-NN algorithm. For this purpose, 1-D values must preserve the closeness of two different coordinates. If I do linear ordering of latitude and longitude values, I couldn't achieve this goal, because closeness will depend on only one value which is placed on the right-most. Let's assume I do linear ordering as lat-lon: