Integrate Amazon SDK

Last Updated on: 19 Sep, 2023

Amazon Android Setup

Follow the instructions below to set up Amazon for Android.

Gradle

Add the following code to your app's build.gradle file inside the dependencies section:

implementation 'com.amazon.android:aps-sdk:9.7.0'
implementation 'ai.meson.sdk.mediation:aps:9.7.0.0-beta4'

Manual

  1. Click here to download the Amazon adapter.
  2. Click here to download the Amazon SDK.

Initialize Amazon SDK

Initialize the Amazon SDK.

Kotlin

AdRegistration.getInstance(APS_APP_ID, activityContext)

Java

AdRegistration.getInstance(APS_APP_ID, this);

Pass Ad Server/Mediator Identifier

Use the setAdNetworkInfo method to pass the mediator.

Kotlin

AdRegistration.setAdNetworkInfo(DTBAdNetworkInfo(DTBAdNetwork.OTHER))

Java

AdRegistration.setAdNetworkInfo(new DTBAdNetworkInfo(DTBAdNetwork.OTHER));

Load Banner Ads from Amazon’s SDK

To integrate Amazon Banner ads into Meson, load the Amazon ad and pass the DTBAdResponse or AdError into the instance of MesonBanner. See the sample code below:

Kotlin

val loader = DTBAdRequest() 
loader.setSizes(DTBAdSize(YOUR_SLOT_WIDTH, YOUR_SLOT_HEIGHT, "YOUR_SLOT_UUID")) 
loader.loadAd(object : DTBAdCallback { 
      override fun onFailure(adError: AdError) { 
            val map = mutableMapOf<String, Any>() 
            map["APS"] = adError 
            mesonBanner.setHeaderBids(map) 
            mesonBanner.load() 
     } 

      override fun onSuccess(dtbAdResponse: DTBAdResponse) { 
            val map = mutableMapOf<String, Any>() 
            map["APS"] = dtbAdResponse 
            mesonBanner.setHeaderBids(map) 
            mesonBanner.load() 
     } 
})

Java

final DTBAdRequest adLoader = new DTBAdRequest(); 

adLoader.setSizes(new DTBAdSize(YOUR_SLOT_WIDTH, YOUR_SLOT_HEIGHT, "YOUR_SLOT_UUID")); 
adLoader.loadAd(new DTBAdCallback() { 
      @Override 
      public void onFailure(AdError adError) { 
            Map<String, Object> map = new HashMap<>(); 
            map.put("APS", adError); 
            mesonBanner.setHeaderBids(map); 
            mesonBanner.load(); 
     } 


      @Override 
      public void onSuccess(DTBAdResponse dtbAdResponse) { 
             Map<String, Object> map = new HashMap<>(); 
             map.put("APS", dtbAdResponse); 
             mesonBanner.setHeaderBids(map); 
             mesonBanner.load(); 
      } 
});

For the auto-refresh banner ads, you must load and pass the Amazon DTBAdResponse or AdError in onHeaderBidExpired callback. See the sample code below:

Kotlin

object : MesonBannerAdListener() { 
      ... 
      override fun onHeaderBidExpired(ad: MesonBanner) { 
            // load amazon ad 
            // pass the Amazon DTBAdResponse or AdError by calling MesonBanner#setHeaderBids 
      } 
      ... 
}

Java

new MesonBannerAdListener() { 
      ... 
      @Override 
      public void onHeaderBidExpired(@NonNull MesonBanner mesonBanner) { 
            // load amazon ad 
            // pass the Amazon DTBAdResponse or AdError by calling MesonBanner#setHeaderBids 

 
      } 
      ...
}

Load Interstitial Ads from Amazon's SDK

To integrate Amazon Interstitial ads into Meson, load the Amazon ad and pass the DTBAdResponse or AdError into the instance of MesonInterstitial. See the sample code below:

Kotlin

val loader = DTBAdRequest() 
loader.setSizes(DTBInterstitialAdSize("YOUR_SLOT_UUID")) 
loader.loadAd(object : DTBAdCallback { 
      override fun onFailure(adError: AdError) { 
            val map = mutableMapOf<String, Any>() 
            map["APS"] = adError 
            mesonInterstitial.setHeaderBids(map) 
            mesonInterstitial.load() 
  }


      override fun onSuccess(dtbAdResponse: DTBAdResponse) { 
            val map = mutableMapOf<String, Any>() 
            map["APS"] = dtbAdResponse 
            mesonInterstitial.setHeaderBids(map) 
            mesonInterstitial.load() 
      } 
})

Java

final DTBAdRequest adLoader = new DTBAdRequest(); 
adLoader.setSizes(new DTBInterstitialAdSize("YOUR_SLOT_UUID")); 
adLoader.loadAd(new DTBAdCallback() { 
      @Override 
      public void onFailure(AdError adError) { 
             Map<String, Object> map = new HashMap<>(); 
             map.put("APS", adError); 
             mesonInterstitial.setHeaderBids(map); 
             mesonInterstitial.load(); 
      } 
 
 
      @Override 
      public void onSuccess(DTBAdResponse dtbAdResponse) { 
             Map<String, Object> map = new HashMap<>(); 
             map.put("APS", dtbAdResponse); 
             mesonInterstitial.setHeaderBids(map); 
             mesonInterstitial.load(); 
      } 
});

Load Rewarded Ads from Amazon’s SDK

To integrate Amazon video ads into Meson, load the Amazon ad and pass the DTBAdResponse or AdError into the instance of MesonInterstitial. See the sample code below:

Kotlin

val loader = DTBAdRequest() 
loader.setSizes(DTBVideo(PLAYER_WIDTH, PLAYER_HEIGHT, "YOUR_SLOT_UUID")) 
loader.loadAd(object : DTBAdCallback { 
      override fun onFailure(adError: AdError) { 
            val map = mutableMapOf<String, Any>() 
            map["APS"] = adError 
            mesonInterstitial.setHeaderBids(map) 
            mesonInterstitial.load() 
     }

      override fun onSuccess(dtbAdResponse: DTBAdResponse) { 
            val map = mutableMapOf<String, Any>() 
            map["APS"] = dtbAdResponse 
            mesonInterstitial.setHeaderBids(map) 
            mesonInterstitial.load() 
     } 
})

Java

final DTBAdRequest adLoader = new DTBAdRequest(); 
adLoader.setSizes(new DTBVideo(PLAYER_WIDTH, PLAYER_HEIGHT,"YOUR_SLOT_UUID")); 
adLoader.loadAd(new DTBAdCallback() { 
      @Override 
      public void onFailure(AdError adError) { 
             Map<String, Object> map = new HashMap<>(); 
             map.put("APS", adError); 
             mesonInterstitial.setHeaderBids(map); 
             mesonInterstitial.load(); 
      } 
 
 
      @Override 
      public void onSuccess(DTBAdResponse dtbAdResponse) { 
             Map<String, Object> map = new HashMap<>(); 
             map.put("APS", dtbAdResponse); 
             mesonInterstitial.setHeaderBids(map); 
             mesonInterstitial.load(); 

} 
});