Create new Project in eclipse.
import Google Play Services library into your workspace.
add Google Play Services library into your project.
Right Click on project than open “property” window.
Click on “Android” and add library.
Add your Banner and Interstitial id in “strings.xml”
[code lang=”js”]
<string name="banner_id">ca-app-pub-7335882925318194/**********</string>
<string name="interstitial_id">ca-app-pub-7335882925318194/**********</string>
[/code]
Give permission for internet inside “manifest.xml”.
[code lang=”js”]
<uses -permission android:name="android.permission.INTERNET"></uses>
[/code]
Copy and paste these lines into you manifest.xml under
[code lang=”js”] android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<meta -data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
[/code]
Create a xml file inside “layout” folder which is under “res” folder. Give file name as “banner_adview.xml”.
Copy and paste these codes into “banner_adview.xml”
[code lang=”js”]
< ?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com .google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_id"
android:visibility="visible"></com>
</linearlayout>
[/code]
include “banner_adview.xml” into your “activity_main.xml” by adding these lines into “activity_main.xml”
[code lang=”js”]
<include layout="@layout/banner_adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"></include>
[/code]
create “InterstitialAd” variable into “MainActivity.java”.
[code lang=”js”]
private InterstitialAd interstitial;
add these lines to integrate banner adview into "onCreate()"
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder().build();
adView.loadAd(request);
interstitial = new InterstitialAd(getBaseContext());
interstitial.setAdUnitId(getResources().getString(R.string.interstitial_id));
interstitial.loadAd(request);
and finally add these line for interstitial ad on back pressed button.
@Override
public void onBackPressed() {
if(interstitial.isLoaded()){
interstitial.show();
}
super.onBackPressed();
}
[/code]
Run your project and check you have successfully added Admob into your app.
Tags: Admob in Android App
Warning: _() expects exactly 1 parameter, 2 given in /home2/mobilemeri7/public_html/wp-content/themes/mobilemerit/comments.php on line 28