Admob integration into Android application (Google advertisements )

    In Activity file add the below code

AdView mAdView = (AdView) rootView.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);


Declare in your xml layout file wherever you want to place advertisement

     <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_weight="1"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id" >

    </com.google.android.gms.ads.AdView>


Manifest declaration :

 <!--Include the AdActivity configChanges and theme. -->
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"

            android:theme="@android:style/Theme.Translucent" />



in strings.xml
declare banner ad unit id
<string name="banner_ad_unit_id">ca-app-pub-8076328522522776/3847247228</string>


Now ready to see ads in the application.

Comments

Popular posts from this blog

What is Android ?