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

Migration from Proxmox to Openstack

I needed to migrate virtual machines in proxmox to openstack. VMs are in raw format. I needed to take some actions for a succesfull migration. I have perform all actions on Ubuntu 12.04 with virt-manager. qemu-kvm is installed. Here is the list of actions that I took: First, close the machine and copy the image file into your Ubuntu. Convert raw image to qcow2 format: qemu-img convert -O qcow2 image1.raw image1.qcow2 You need the image in qcow2 format for compatibility with openstack platform.  Open the converted image in virt-manager. Before opening, edit disk options. Under ' advanced options ' section, select ' qcow2 ' as ' storage forma t '. Start the virtual machine. You should see the login screen soon. (If you don't set storage format, vm will not find a bootable device. )   If everything is ok so far, close the vm. Take qcow2 image and upload it into glance. It may take time depending on size of it. After this process is completed, open a

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.

Xposed - How to hook a method with primitive-type parameter

Xposed Framework is a great tool to take actions which Android SDK doesn't provide for developers. One of the great hacks that you can do is hooking a method. You can see parameters given to a method, with many other properties of it. There are some tutorials on Internet, but in this tutorials, they show hooking method without parameters or with class parameters. Its code is: findAndHookMethod("com.android.settings.Settings", lpparam.classLoader, "updateHeaderList", List.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { //your code } });