What an impressive long blog title!
Quattro Wireless Ads has slightly better eCPM than AdMob, and it allows your to put a default image Ads (not clickable). However, its fillrate is unbearably low (50% ~ 90%, typically around 75%, according to my 2 week test). Here, I’m showing you a way to mix Ads from Quattro Wireless, AdMob, and your own Ads.
For information about how to setup Ads on android apps using Quattro Wirelss, click here.
Step 1: Prepare your own banner ads.
Setp 2: Add the following Ads banner in your layout xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<FrameLayout android:layout_width="fill_parent" android:layout_height="50dp" android:gravity="top"> <ImageView android:id="@+id/ownads" android:src="@drawable/banner_ad" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <com.admob.android.ads.AdView android:id="@+id/adMob" android:layout_width="fill_parent" android:layout_alignParentTop="true" android:layout_marginTop="10dp" android:layout_height="fill_parent" /> <com.qwapi.adclient.android.view.QWAdView android:id="@+id/QWAd" android:layout_width="fill_parent" android:layout_height="fill_parent" qwad:siteId="xyz" qwad:publisherId="xyz" qwad:mediaType="banner,text" qwad:displayMode="autoRotate" qwad:placement="top" qwad:animation="fade" /> </FrameLayout> |
Step 3: Implement Quattro’s AdEventsListener so that it always try Quattro’s ads first; if that fails, try Admob, which upon failure will display your own clickable Ads.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import android.content.Context; import android.os.Handler; import android.os.Message; import android.view.View; import com.admob.android.ads.AdView; import com.qwapi.adclient.android.data.Ad; import com.qwapi.adclient.android.data.Status; import com.qwapi.adclient.android.requestparams.AdRequestParams; import com.qwapi.adclient.android.view.AdEventsListener; import com.qwapi.adclient.android.view.QWAdView; public class AdListener implements AdEventsListener { private QWAdView qwAdView; private AdView adMobView; public AdListener(MainActivity context) { qwAdView = (QWAdView) context.findViewById(R.id.QWAd); adMobView = (AdView) context.findViewById(R.id.adMob); } @Override public void onAdClick(Context arg0, Ad arg1) { } @Override public void onAdRequest(Context arg0, AdRequestParams arg1) { } @Override public void onAdRequestFailed(Context arg0, AdRequestParams arg1, Status arg2) { Message.obtain(hideHandler, -1).sendToTarget(); } /** Hide Quattro and request Ads from AdMob when Quattro returns no Ads. */ protected Handler hideHandler = new Handler() { @Override public void handleMessage(Message msg) { qwAdView.setVisibility(View.GONE); adMobView.requestFreshAd(); } }; /** Display Quattro banner when it returns an Ads. */ protected Handler showHandler = new Handler() { @Override public void handleMessage(Message msg) { qwAdView.setVisibility(View.VISIBLE); } }; @Override public void onAdRequestSuccessful(Context arg0, AdRequestParams arg1, Ad arg2) { Message.obtain(showHandler, -1).sendToTarget(); } @Override public void onDisplayAd(Context arg0, Ad arg1) { } } |
Setp 4: Change your activity to include this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
private static final Uri SAME2D_URI = Uri.parse("market://search?q=pname:com.clingmarks.same2dfree"); /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ... ImageView pairupAds = (ImageView) findViewById(R.id.ownads); pairupAds.setOnClickListener(adsListener); // Configures AdMob's Ads AdView ad = (AdView) findViewById(R.id.ad); if (ad!=null){ // Show own ads when there's no AdMob Ads. ad.setGoneWithoutAd(true); // Don't auto request Ads: only do so when Quattro failed. ad.setRequestInterval(0); } // Configures Quattro's Ads AdListener adListener = new AdListener(this); QWAdView qwAdView = (QWAdView) this.findViewById(R.id.QWAd); qwAdView.setAdEventsListener(adListener, false); // whether the listener should run in UI thread. } // Own ads click listener. private View.OnClickListener adsListener = new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW, SAME2D_URI); startActivity(intent); } }; |
Done!
p.s. After the initial post of this blog, Quattro contacted me about the misuse of second parameter in qwAdView.setAdEventsListener method (I was setting it as true which caused significant UI delaying). Thanks for that! I also hope Quattro can provide useful Javadoc as I can’t find them anywhere.


Comments (2)