- Creating Ads Manger for Android - Part 1 - First part of SBCAdManager
- Creating Ads Manger for Android - Part 2 - Finishing SBCAdManager
- Creating Ads Manger for Android - Part 3 - Implementing AdMob
Last time we implemented first ad network - AdMob. Today we will add Madvertise. This network is exactly the reason why we are building some ad systems manager. It seems that Madvertise is focused on some countries of western Europe - Germany, Italy. Earnings are about 0,05 EUR / click, which is not bad. But if your user is in any other location they will not send an ad into his device. This results into low fill rate but if you have ad manager you can just say never mind and skip to other ad network.
Adding Madvertise SDK
To integrate Madvertise SDK into your Eclipse project follow the instructions here. It is enough to follow the instructions until you added Madvertise project into your project as rest may be little bit different for out adds manager.
Last time we already added permissions for INTERNET and ACCESS_NETWORK_STATE. Today we will add optional permissions for reading state of wifi and to roughly detect the location of the user.
Next we need to adjust the manifest file with Madvertise activity. There is also place for token identifying your app. If you just want to test then put word "TestTokn" there. Do not forget to replace it when you are ready to publish.
When implementing AdMob we had to adjust file SBCAdsConstants.java with AdMob ad unit ID. This is not necessary here as we put our Madvertise ad ID directly into manifest file.
MadvertiseSystem.javaNow we are ready to implement the class. We start with imports and variables again:
Instead of AdMob AdListener we are implementing MadvertiseViewCallbackListener this time. SBCAdSystem is our interface that we have to implement for every ad network we want our ad manager to handle. This is the constructor:
SBCAdSystem implementationTo start Madvertise ad network we have to implement start method from SBCAdSystem interface:
Calling setFetchingAdsEnabled with true will launch our request for ad. With the result of this reqest we will be notified through MadvertiseViewCallbackListener methods.
Next we need methods to stop and destroy this ad system in case we are switching to another one.
Finally there is method for setting the events listener and for processing keys. The later will again have no implementation for Madvertise:
MadvertiseViewCallbackListener implementationNow comes the implementation of the interface that is part of Madvertise SDK. Again it is very simple as most of the methods will just notify our listener (that means our ad manager that is implementing it) and the rest is more or less just some debug output to watch in LogCat if everything is going well.
Today we added next ad network to our ad manager system. Next time we will ad Leadbolt network. You can now adjust the constants in SBCAdsConstants.java file so it handles two networks and with probability settings you can say how many percent of your users will ask for AdMob or Madvertise ad.