Aquí se describe cómo añadir Mobfox a una aplicación Android que, a su vez, usará Admob como backfill.

Paso 1:

Añadir los SDK de Admob y Mobfox al proyecto poniendo los respectivos jars en la carpeta “libs”.

Paso 2:

Editar el fichero AndroidManifest.xml y añadir lo siguiente:

<activity android:name="com.mobfox.sdk.InAppWebView"/>
<activity android:name="com.google.ads.AdActivity"
          android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
          android:configChanges="orientation|keyboard|keyboardHidden"
         />


Paso 3:

Añadir la siguiente vista en el layout correspondiente de main.xml:

<RelativeLayout
   android:id="@+id/mobfoxContent"
   android:layout_width="fill_parent"
   android:layout_height="50dp"
   android:layout_centerHorizontal="true"
   android:layout_alignParentBottom="true" >
</RelativeLayout>


Paso 4:

Añadir los siguiente imports en la Activity:

Import com.google.ads.Ad;
Import com.google.ads.AdListener;
Import com.google.ads.AdRequest;
Import com.google.ads.AdSize;
Import com.google.ads.AdView;
Import com.google.ads.AdRequest.ErrorCode;
Import com.mobfox.sdk.BannerListener;
Import com.mobfox.sdk.MobFoxView;
Import com.mobfox.sdk.Mode;
Import com.mobfox.sdk.RequestException;


Paso 5:

Añadir las siguientes declaraciones:

private final static String ADMOB_PUBLISHER_ID = "";
private final static String MOBFOX_PUBLISHER_ID = "";
private ViewFlipper viewFlipper;
private MobFoxView mobfoxView;
private AdView adMobView;
private AdRequest adMobRequest;
private final static int REFRESH_AD = 101;
private final static long REFRESH_INTERVAL = 30000;
private Handler refreshHandler;
private Looper refreshLooper;
private RelativeLayout layout;


Paso 6:

Añadir lo siguiente al método onCreate():

boolean includeLocation = false;
boolean useAnimation = true;

mobfoxView = new MobFoxView(this, MOBFOX_PUBLISHER_ID, Mode.LIVE, includeLocation, useAnimation);
mobfoxView.setBannerListener(this);

adMobView = new AdView(this, AdSize.BANNER, ADMOB_PUBLISHER_ID);
adMobView.setAdListener(this);
adMobRequest = buildAdMobRequest();

viewFlipper = new ViewFlipper(this) {
    @Override
    protected void onDetachedFromWindow() {
        try {
            super.onDetachedFromWindow();
        }
        catch (IllegalArgumentException e) {
            stopFlipping();
        }
    }
};

viewFlipper.addView(mobfoxView);
viewFlipper.addView(adMobView);

if (useAnimation)
{
    Animation fadeInAnimation =
        new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
        Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    fadeInAnimation.setDuration(1000);
    Animation fadeOutAnimation =
        new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
        Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f);
    fadeOutAnimation.setDuration(1000);
    viewFlipper.setInAnimation(fadeInAnimation);
    viewFlipper.setOutAnimation(fadeOutAnimation);
    viewFlipper.setAnimateFirstView(true);
}

//Show MobFoxView viewFlipper.setDisplayedChild(0);
layout = (RelativeLayout) findViewById(R.id.mobfoxContent);
layout.addView(viewFlipper);
Thread refreshThread = new Thread(){
    @Override
    public void run() {
        Looper.prepare();
        refreshLooper=Looper.myLooper();
        refreshHandler = new Handler(refreshLooper) {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                case REFRESH_AD:
                    {
                        mobfoxView.loadNextAd();
                        break;
                    }
                }
            }
        };
        Looper.loop();
    }
};
refreshThread.start();


Paso 7:

Añadir los siguientes métodos a la Activity

public AdRequest buildAdMobRequest()
{
    AdRequest adMobRequest =
    new AdRequest();
    //Add targeting info if you like
    //adMobRequest.setGender(Gender.FEMALE);
    //adMobRequest.setBirthday(birthDate);
    //adMobRequest.setLocation(location);
    adMobRequest.addKeyword("game");
    adMobRequest.setTesting(false);
    return adMobRequest;
}

@Override
protected void onPause() {
    super.onPause();
    if (refreshHandler != null)
    {
        refreshHandler.removeMessages(REFRESH_AD);
    }
    if (adMobView!=null)
    {
        adMobView.stopLoading();
    }
    mobfoxView.pause();
}

@Override
protected void onResume() {
    super.onResume();
    if (refreshHandler != null)
    {
        refreshHandler.removeMessages(REFRESH_AD);
        refreshHandler.sendEmptyMessage(REFRESH_AD);
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (refreshLooper != null)
    {
        refreshLooper.quit();
        refreshLooper = null;
        refreshHandler = null;
    }
}

@Override
public void bannerLoadSucceeded() {
    this.runOnUiThread(new Runnable() {
        public void run() {
            if (viewFlipper.getCurrentView()!=mobfoxView)
            {
                viewFlipper.setDisplayedChild(0);
            }
        }
    });
}

//Mobfox events
@Override
public void noAdFound() {
    this.runOnUiThread(new Runnable() {
        public void run() {
        }
    });
    try
    {
        adMobView.loadAd(adMobRequest);
    }
    catch (Exception ex)
    {
        if (refreshHandler!=null)
        {
            refreshHandler.sendEmptyMessageDelayed(REFRESH_AD, REFRESH_INTERVAL);
        }
    }
}

@Override
public void bannerLoadFailed(RequestException e) {
    this.runOnUiThread(new Runnable() {
        public void run() {
        }
    });
    try
    {
        adMobView.loadAd(adMobRequest);
    }
    catch (Exception ex)
    {
        if (refreshHandler!=null)
        {
            refreshHandler.sendEmptyMessageDelayed(REFRESH_AD, REFRESH_INTERVAL);
        }
    }
}

//Admob events
@Override
public void onReceiveAd(Ad arg0) {
    this.runOnUiThread(new Runnable() {
        public void run() {
            if (viewFlipper.getCurrentView()!=adMobView)
            {
                viewFlipper.setDisplayedChild(1);
            }
        }
    });
    if (refreshHandler!=null)
    {
        refreshHandler.sendEmptyMessageDelayed(REFRESH_AD, REFRESH_INTERVAL);
    }
}

@Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
    this.runOnUiThread(new Runnable() {
        public void run() {
        }
    });
    if (refreshHandler!=null)
    {
        refreshHandler.sendEmptyMessageDelayed(REFRESH_AD, REFRESH_INTERVAL);
    }
}

@Override
public void onDismissScreen(Ad arg0) {
    // TODO Auto-generated method stub
}
@Override
public void onLeaveApplication(Ad arg0) {
    // TODO Auto-generated method stub
}
@Override
public void onPresentScreen(Ad arg0) {
    // TODO Auto-generated method stub
}


Paso 8:

La Activity debe implementar BannerListener y AdListener, con lo que quedaría algo parecido a esto:

public class MyAndroidApplication extends Activity implements BannerListener, AdListener {


Paso 9:

Añadir los IDs de publisher correspondientes:

private final static String ADMOB_PUBLISHER_ID = "";
private final static String MOBFOX_PUBLISHER_ID = "";

¡Hecho!

Ahora tu aplicación ya recibe anuncios de Mobfox usando Admob como backfill.