Switching from Google Ads to AppFlood in a LibGDX application

adsGoogle Ads (aka AdMobs) is one of the most well known ad system used by developers to make some money with free apps/games. But other solutions exist and can be real alternatives.

I used to have some problems with revenues from Google Ads so i made some research and discovered App Flood.
The documentation on services proposed were clear and the “how-to” guide looked very clear and simple. So i decided to give a try to AppFlood in one of my LibGDX game.
After a quick registration on the web site to register my app and get my keys, i started implementing the API in my code. I was well surprised to see how much all is working out of the box and all the options proposed (banner, video ads, revenue on APK installation).
But how integrate an adsystem with a libgdx application?
Indeed with libgdx, the android application is just a wrapper to your main application in order to run it on android devices.
The adsystem should be plugged on the android layer through the application manifest
So first, add the required library in your android project:

  • Download somewhere the jar (as it will not be available on maven central repo)
  • and add the dependency:

Then following App flood doc, modify your AndroidManifest file:

The idea is to have a callback in your “core” code in order to call the ads system when you need to (for example screen transition).
So just create a simple interface for this in core module:

Modify your main application class to allow android application to registered the ad system:

Then implements this class in your Main android activity. Don’t forget to call the registering method on the main application.

Then whenever you decider you just have to call the method showAds() from your core code but dont forget to check if an ads system was registered otherwise you will get a NullPointerException

Sounds easy no?