Followers

Sunday, February 15, 2015

Android Admob Programmatically.

Android Admob Programmatically.
Hi Friends Today we are going to see about how to add admob in our Android Application.

Ad Mob released Ad Mob SDK v6.0.1 for android a few days ago.

Download the latest Google Admob Ads SDK from following link

https://developers.google.com/mobile-ads-sdk/download
and paste it in your project libs folder.

Your Manifest file should contain the following permissions

  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

And the following activity

<activity android:name="com.google.ads.AdActivity"/>

Your Activity will be look like something below.

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

import com.google.ads.*;

public class AdmobExample extends Activity {
    /** Called when the activity is first created. */  
    private AdView myAdView;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        myAdView = new AdView(this, AdSize.BANNER, "youradmob id. ");
       
        //get layoutView
        LinearLayout rootView = (LinearLayout)this.findViewById(R.id.rootViewGroup);
        LinearLayout.LayoutParams layoutParams = new LayoutParams(480, 75);
       
        rootView.addView(myAdView, 0, layoutParams);      
       
        AdRequest re = new AdRequest();
        re.setGender(AdRequest.Gender.FEMALE);      
       
        myAdView.loadAd(re);
    }
}
Your xml file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal"
 
    >
   
   
    <LinearLayout  android:layout_width="fill_parent"
        android:layout_alignParentBottom="true"
         android:id="@+id/rootViewGroup"
        android:layout_height="wrap_content" >
       
       
    </LinearLayout>
   

</RelativeLayout>

0 comments:

Post a Comment

Add


Visitor


counters

 
Twitter Bird Gadget