Sudeep's Blog

Disorganized Thoughts in Organized Manner

Adding Banner Ad to Android App
Here is how you can add banner ad to Android app.
  • Create an account on AdMob: Provide your bank details etc etc.
  • Create an ad campaign: AdMob makes it extremely easy to create a campaign. After walking through the process you will end up with an ad id of the form: ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY
  • Finally, add this code to your MainActivity: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Window window = getWindow(); RelativeLayout adsLayout = new RelativeLayout(this); RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); adsLayout.setGravity(Gravity.BOTTOM); AdView adView = new AdView(this, AdSize.SMART_BANNER, "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY"); adsLayout.addView(adView); AdRequest newAdReq = new AdRequest(); adView.loadAd(newAdReq); window.addContentView(adsLayout, lp2); }
Back to Home