2.) Create a project MyAdMob.
3.) In your project’s root directory create a subdirectory lib. Copy the AdMob JAR (GoogleAdMobAdsSdk.jar) file into that lib directory.
4.) Right-click on your project from the Package Explorer tab and select Properties.
5.) Select Java Build Path from left panel and Select Libraries tab from the main window.
6.) Click on Add JARs.
7.) Select the JAR copied to the libs directory, Click OK to add the SDK to your Android project.
8.) Add some relevant permissions in AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.sample.MyAdMob" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MyAdMob" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"android:configChanges="keyboard|keyboardHidden|orientation" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Project name: MyAdMob
Build Target: Android 2.1
Application name: MyAdMob
Package name: com.sample.MyAdMob
Create Activity: MyAdMob
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import android.os.Bundle;
import android.widget.LinearLayout;
{
private static final String MY_BANNER_UNIT_ID = "a14db01ee16f245";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Lookup R.layout.main
LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.BANNER, MY_BANNER_UNIT_ID);
layout.addView(adView);
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
}
}