Using Amazon Mobile Ads API with Other SDKs

Loading Ads from Multiple SDKs

The Amazon Mobile Ads API can be used in conjunction with other Ad SDKs. Amazon recommends providing the Amazon Mobile Ad Network with the first look. Before loading an Amazon Ad you'll want to implement an AdListener, which has callbacks for success and failure. If no ads were available from the Amazon Mobile Ad Network, then the AdListener.onAdFailedToLoad callback function can be used to call another Ad SDK.

Below is a simple example of a program that first tries to load an ad from the Amazon Ad Network. On failure, it makes a second ad request via AdMob's SDK.

	public class SimpleAdActivity extends Activity implements AdListener {
	    private ViewGroup adViewContainer;
	    private com.amazon.device.ads.AdLayout amazonAdView;
	    private com.google.ads.AdView admobAdView;
	    private boolean amazonAdEnabled;
	    ...
	  
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.main);
	 
	        com.amazon.device.ads.AdRegistration.setAppKey(APP_ID);
	       
	        // Initialize ad views
	        amazonAdView = new com.amazon.device.ads.AdLayout(this, com.amazon.device.ads.AdSize.SIZE_320x50);
	        amazonAdView.setListener(this);
	        admobAdView = new com.google.ads.AdView(this, com.google.ads.AdSize.BANNER, MY_AD_UNIT_ID);       
	 
	        // Initialize view container
	        adViewContainer = (ViewGroup)findViewById(R.id.ad_view);
	        amazonAdEnabled = true;
	        adViewContainer.addView(amazonAdView);
	 
	        amazonAdView.loadAd(new com.amazon.device.ads.AdTargetingOptions());
	    }
	 
	    ...
	 
	    public void refreshAd()
	    {
	        amazonAdView.loadAd(new com.amazon.device.ads.AdTargetingOptions());
	    }
	 
	    public void onAdLoaded(com.amazon.device.ads.AdLayout view, AdProperties adProperties)
	    {
	        if (!amazonAdEnabled)
	        {
	            amazonAdEnabled = true;
	            adViewContainer.removeView(admobAdView);
	            adViewContainer.addView(amazonAdView);
	        }
	    }
	 
	    public void onAdFailedToLoad(com.amazon.device.ads.AdLayout view, AdError error)
	    {
	        //Call Admob SDK for Backfill
	        if (amazonAdEnabled)
	        {
	            amazonAdEnabled = false;
	            adViewContainer.removeView(amazonAdView);
	            adViewContainer.addView(admobAdView);
	        }
	        
	        admobAdView.loadAd(new com.google.ads.AdRequest());
	    }
	}


Mediator SDK Integration

Ads from the Amazon Mobile Ad Network can also be retrieved through select mediator SDKs. General guidelines for integration are listed below.

Note: The following guidelines only apply to users attempting to load ads from the Amazon Mobile Ad Network through a third party mediator SDK.

1) Apps that reload ads in such a way that new ads replace existing ads on the same screen (for example, apps that reload ads on a time interval) will need to take special measures to ensure that new ads cannot load while the user is already interacting with an expanded rich media ad. This can be accomplished in a number of ways:

  • (RECOMMENDED) Introduce logic to prevent ad loading actions from initiating if an ad has expanded. For example, you can define a boolean variable isExpanded that is set to true upon ad expansion and set to false upon ad collapse, and you can then check to make sure that isExpanded equals false as a condition for requesting an ad from the mediator SDK. You will need to combine this solution with one of the others listed below to handle the case where an ad begins loading before the current ad is expanded.
  • (RECOMMENDED) Load new ads in a separate, invisible ad view, swapping that ad view with the current one only after the ad has finished loading. We recommend you combine this solution with the above solution to ensure that new ads do not begin loading while the current ad is expanded.
  • (RECOMMENDED) Remove automatic ad refresh behavior except in cases where the parent view is destroyed.
  • Destroy the existing ad view when loading a new ad.
  • Disable clicking while an ad is in the process of loading, and re-enable only after a new ad has loaded.
2) You must ensure that the AdActivity activity is declared in your AndroidManifest.xml file. See Step 2 of the Quick Start Guide for details.

3) Remember that all apps utilizing the Amazon Mobile Ad Network, even those that do so through a mediator's SDK, must pass the criteria outlined in the Developer Launch Checklist prior to submission. You will need to contact your mediator to enable Amazon Test ads before testing starts and you will also need to contact your mediator to disable Amazon Test ads after testing has been completed.

Please contact your mediator for specific supplemental information regarding integrating the Amazon Mobile Ad Network through its SDK.



Return to the Amazon Mobile Ads API Overview

Unavailable During Maintenance