The Amazon Mobile Ads API allows you to easily place high-quality display ads from the Amazon Mobile Ad Network into your Android and Kindle Fire apps. Successfully monetizing your apps with ads depends on several factors, one of the biggest being the ad fill rates you receive. A common practice is to use multiple ad networks so that if you are unable to fill an ad with one network you can request an ad from another one.
I thought it would be helpful to offer some guidance on how you can implement multiple ad networks into your own apps. This should help increase your fill rates as well as giving you the opportunity to show ads to customers were the Amazon Mobile Ad Network currently does not serve ads.
Let’s get started!
Setting up the App Manifest and Layout
The first thing you will need to do is follow the guidelines for including the correct Android network permissions and ad Activity as described here. Since you are going to include AdMob ads as well you will need to define that activity after our Amazon Ad as seen below.
You will also need to make sure you have set up the Amazon AdLayout inside of your layout file like below.
Declaring Multiple Ad Networks
Verify that both ad networks have been added to your Android project and set for export as seen below. For purposes of this demo, I will be using version 6.4.1 of the AdMob SDK and version 5.1.153 of the Amazon Mobile Ads API.”
Depending on what ad network SDK you are working with, many of the classes may be named similarly to the ones used in Amazon Mobile Ads API . You will need to be extremely careful when referencing individual classes and I recommended using fully qualified namespaces as seen below.
Displaying an Amazon Ad
Displaying an ad with the Amazon Mobile Ads API is as simple as creating and adding an Amazon AdView to the layout, setting any optional targeting properties and then calling the loadAd method of the AdView.
In the example below I am setting the ad to target a twenty five year old male and using a simple fixed rate timer to refresh the ad over time using a fixed schedule timer.
I have also turned logging on by setting the AdRegistration logging flag to true. This will give us detailed information in LogCat about the ads being served.
Here are some screenshots of the Amazon ads being loaded on a Kindle Fire HDX device:
Here is an example of the Amazon ad information being written to LogCat:
Checking if an Amazon Ad was served
If an Amazon ad has not been served within the timeout period it will call the onAdFailedToLoad() method. The default timeout is 20 seconds but you can change this to a different value (defined in milliseconds) by setting a property on the AdView itself. I recommend doing this while testing so that you can force the ad mediation to happen.
In the code below you will see I have set the timeout to be 100 milliseconds, which will always cause the ad to fail while I am debugging my secondary ad network. Once I have seen ads being loaded from both networks I can set this back to a more reasonable value.
Inside the onAdFailedToLoad method I log the ad error message I received, remove the Amazon view from the UI, load the AdMob view and then I have it request an ad.
Here are some screenshots of the AdMob ad being loaded on a Kindle Fire HDX device:
Here is an example of the AdMob information being written to LogCat:
Setting an Ad Timeout
The Amazon Mobile Ad Network recommends loading a new ad on screen navigations and device orientation changes when the ad view changes size. You may also want to refresh the ad after a set time interval. In this case, the Amazon Mobile Ad Network recommends a refresh rate of 30 to 60 seconds. Faster ad refresh intervals could result in blocked ad requests.
Please note that the Amazon Mobile Ads API does not provide any built-in functionality for automatically refreshing ads. The timeout value of the Amazon AdView is the amount of time it will try to get a new ad for you before calling the onAdFailedToLoad method. This will not auto refresh the ad it will only change the amount of time it spends trying to load an ad.
You will need to create your own timer system to refresh the ad or some other way inside of your app. In the code example above I used a timer on a fixed rate schedule for demo purposes, but there is no limitation to the way you could handle this in your own apps. For example, every time a player reaches a new level in your game you briefly display an ad.
Hopefully you have seen how easy it is to set up ad mediation with the Amazon Mobile Ads API and third party ad SDKs in your own apps. You can read more details on working with other ad SDKs here on our developer portal. You can also get more detailed information about the Amazon Mobile Ads API itself and sign up here.