Sunday, June 7, 2015

AdMob interstial adapter for Appnext

I needed intergration Appnext into AdMob mediation bt there was not AdMob adapter, so I wrote one. Please note this adapter uses Appnext's Activities & not in-activity popups.


package com.appnext.appnextsdk;

import android.content.Context;
import android.os.Bundle;

import com.google.android.gms.ads.mediation.MediationAdRequest;
import com.google.android.gms.ads.mediation.customevent.CustomEventInterstitial;
import com.google.android.gms.ads.mediation.customevent.CustomEventInterstitialListener;

public class AppnextAdMobAdapter implements CustomEventInterstitial {
 private CustomEventInterstitialListener mCustomEventInterstitialListener;
 private String mPlacementId;
 private Context mContext;
 
 @Override
 public void onDestroy() {
 }

 @Override
 public void onPause() {
 }

 @Override
 public void onResume() {
 }

 @Override
 public void requestInterstitialAd(Context context,
            CustomEventInterstitialListener listener,
            String serverParameter,
            MediationAdRequest mediationAdRequest,
            Bundle customEventExtras) {
  mContext = context;
  mPlacementId = serverParameter;
  mCustomEventInterstitialListener = listener;

  if (mCustomEventInterstitialListener != null)
   mCustomEventInterstitialListener.onAdLoaded();
 }

 @Override
 public void showInterstitial() {
  PopupActivity.setAdLoadInterface(new OnAdLoadInterface() {   
   @Override
   public void adLoaded() {
    if (mCustomEventInterstitialListener != null)
     mCustomEventInterstitialListener.onAdLoaded();
   }
  });
  PopupActivity.setNoAdsInterface(new NoAdsInterface() {   
   @Override
   public void noAds() {
    if (mCustomEventInterstitialListener != null)
     mCustomEventInterstitialListener.onAdFailedToLoad(0);
   }
  });
  PopupActivity.setPopupOpenedInterface(new PopupOpenedInterface() {   
   @Override
   public void popupOpened() {
    if (mCustomEventInterstitialListener != null)
     mCustomEventInterstitialListener.onAdOpened();
   }
  });
  PopupActivity.setPopupClickedCallback(new PopupClickedInterface() {
   @Override
   public void popupClicked() {
    if (mCustomEventInterstitialListener != null)
     mCustomEventInterstitialListener.onAdClicked();
   }
  });
  PopupActivity.setPopupClosedCallback(new PopupClosedInterface() {   
   @Override
   public void popupClosed() {
    if (mCustomEventInterstitialListener != null)
     mCustomEventInterstitialListener.onAdClosed();
   }
  });

  Appnext.showPopupInActivity(mContext, mPlacementId, false);
 }
}

2 comments:

Giri Mani 2 said...

This blog explains the details about what happened after the expressions. This gives the details of the thinking next what to do. All that are discussed and provide a grateful talk.
Hadoop Training in Chennai

Aasha said...

Wow amazing i saw the article with execution models you had posted. It was such informative.By explaining this type we can identify the concepts easily. So thank you for this sharing.

App Store Optimization Services in Chennai