A lot of people asked me how I implement the switch of Madvertise to another ad network. Here is how I do it:
I’m doing this example using an AdMob and an Madvertise view. Of course you can use any other similar networks like Adwhirl or Mobclix as well but I’m assuming you are familiar with including the two SDKs you are using.
At first we need a layout resource, here it is:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" xmlns:mad="http://schemas.android.com/apk/res/com.andlabs.gi" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.google.ads.AdView android:id="@+id/admad" android:layout_width="match_parent" android:layout_height="wrap_content" ads:adUnitId="y0ur4dun1t1dh3r3" ads:adSize="BANNER" ads:loadAdOnCreate="true" /> <de.madvertise.dev.android.MadView android:id="@+id/madad" android:layout_width="match_parent" android:layout_height="Wrap_content" mad:isTestMode="false" mad:backgroundColor2="#000000" mad:textColor="#FFFFFF" mad:bannerType="mma" mad:deliverOnlyText="false" android:visibility="gone" /> </FrameLayout>
Pretty basic. A Madvertise and an AdMob view. Next step: Get them in your Activity:
private MadView mMadView; private AdView mAdmView;
@Override public void onCreate(Bundle bundle) { super.onCreate(bundle);
/* ... */
mAdmView = (AdView)findViewById(R.id.admad); mMadView = (MadView)findViewById(R.id.madad); }
That’s easy too. Next, register an MadViewCallbackListener and switch the views the way you need it. As you have seen the MadView is invisible at the beginning. I assume that Madvertise always brings in more money, so when I receive an ad by them, I set the AdMob view to invisible and the MadView to visible. That’s essentially it:
mMadView.setMadViewCallbackListener(new MadViewCallbackListener() { @Override public void onLoaded(boolean success, MadView arg1) { if (success) { if(D) { Log.d(this.getClass().getSimpleName(), "MadAd Received"); } if (mAdmView.getVisibility() == View.VISIBLE) { mAdmView.setVisibility(View.GONE); } mMadView.setVisibility(View.VISIBLE); } else { if(D) { Log.d(this.getClass().getSimpleName(), "No MadAd Received"); } mMadView.setVisibility(View.GONE); } } });
Not a big deal. And that’s all. Now you have your own little meta ad network.
Please feel free to leave your experiences, questions or suggestions in the comments.