Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 2.33 KB  |  hits: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Custom Events in Admob Mediattion adding unsupported Ad Networks
  2. public class CustomEvent implements CustomEventBanner, AdListener{
  3.  
  4. private CustomEventBannerListener bannerListener;
  5. private AdView adView;
  6.  
  7. @Override
  8. public void requestBannerAd(final CustomEventBannerListener listener,
  9.         final Activity activity,
  10.         String label,
  11.         String serverParameter,
  12.         AdSize adSize,
  13.         MediationAdRequest mediationAdRequest) {
  14.     // Keep the custom event listener for use later.
  15.     this.bannerListener = listener;
  16.  
  17.     // Determine the best ad format to use given the adSize. If the adSize
  18.     // isn't appropriate for any format, an ad will not fill.
  19.     AdSize bestAdSize = adSize = adSize.findBestSize(
  20.             AdSize.BANNER,
  21.             AdSize.IAB_BANNER,
  22.             AdSize.IAB_LEADERBOARD,
  23.             AdSize.IAB_MRECT,
  24.             AdSize.IAB_WIDE_SKYSCRAPER);
  25.     if (bestAdSize == null) {
  26.         listener.onFailedToReceiveAd();
  27.         return;
  28.     }
  29.  
  30.     // Initialize an AdView with the bestAdSize and the publisher ID.
  31.     // The publisher ID is the server parameter that you gave when creating
  32.     // the custom event.
  33.     this.adView = new AdView(activity, bestAdSize, serverParameter);
  34.  
  35.     // Set the listener to register for events.
  36.     this.adView.setAdListener(this);
  37.     // Generate an ad request using custom targeting values provided in the
  38.     // MediationAdRequest.
  39.     AdRequest adRequest = new AdRequest()
  40.     .setBirthday(mediationAdRequest.getBirthday())
  41.     .setGender(mediationAdRequest.getGender())
  42.     .setKeywords(mediationAdRequest.getKeywords())
  43.     .setLocation(mediationAdRequest.getLocation());
  44.     if (mediationAdRequest.isTesting()) {
  45.         adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
  46.     }
  47.  
  48.     // Load the ad with the ad request.
  49.     this.adView.loadAd(adRequest);
  50. }
  51.  
  52. @Override
  53. public void onReceiveAd(Ad ad) {
  54.     this.bannerListener.onReceivedAd(this.adView);
  55. }
  56.  
  57. @Override
  58. public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {
  59.     this.bannerListener.onFailedToReceiveAd();
  60. }
  61.  
  62. @Override
  63. public void onPresentScreen(Ad ad) {
  64.     this.bannerListener.onClick();
  65.     this.bannerListener.onPresentScreen();
  66. }
  67.  
  68. @Override
  69. public void onDismissScreen(Ad ad) {
  70.     this.bannerListener.onDismissScreen();
  71. }
  72.  
  73. @Override
  74. public void onLeaveApplication(Ad ad) {
  75.     this.bannerListener.onLeaveApplication();
  76. }
  77.  
  78.  
  79. }