Ad Mixer (I) - How to mix AdMob Ads and your own clickable Ads

By admin | Jan 31, 2010

If you are an AdMob publisher, you will know how fluctuating their fillrates are: mine varies from 40% to 100%. What’s even worse is that they don’t support default Ads. So I decide to mix in mine:

For information about how to setup Ads on android apps using AdMob, click here.

Step 1: Prepare your own banner ads (320×50 or 480×50. Note AdMob’s ads has a fixed height of 50 pixels).

Step 2: Replace your AdView with the following framelayout in your layout xml:

1
2
3
4
5
6
7
8
9
10
11
12
<FrameLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:gravity="center_horizontal">
 
    <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/ad"
	android:layout_width="fill_parent" android:layout_height="50dp"
	android:layout_alignParentBottom="true"
        app:backgroundColor="#000000" app:textColor="#FFFFFF" />
</FrameLayout>

Step 3: 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
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);
	AdView ad = (AdView) findViewById(R.id.ad);
	if (ad!=null){
                // Show own ads when there's no AdMob Ads.
		ad.setGoneWithoutAd(true);
		ad.setRequestInterval(60);
		// Make the ad disappear with the text or a new ad appear.
		ad.requestFreshAd();
	}
}
 
private View.OnClickListener adsListener = new View.OnClickListener() {
	public void onClick(View v) {
		Intent intent = new Intent(Intent.ACTION_VIEW, SAME2D_URI);
		startActivity(intent);
	}
};

Done!

1 Comment so far
  1. padmakumar March 18, 2010 10:17 am

    Excatly this code i want

    thanx boss………..

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 - 2009 ClingMarks