To get started, we are going to need to setup a couple of online accounts.
AdMob
- Create an account at AdMob.
- From your dashboard, click on "Sites & Apps".
- Click on "Add Site/App".
- Click on "Android App"
- Fill in the form (I'd ignore the URL for now but eventually it will look like http://market.android.com/search?q=pname:com.example.ExampleApp)
- Hit "Continue"
- Click on "Download AdMob Android SDK"
- Extract it to the disk somewhere and navigate to it from the command line
C:\java\admob-sdk-android> mvn install:install-file -Dfile=admob-sdk-android.jar -DgroupId=com.admob.android.ads -DartifactId=AdMobAndroid -Dversion=20100331 -Dpackaging=jar
- Note: I got the version from the top of the Changelog.txt file
- Click on "Go to Sites/Apps"
- Under the row for your new app, click on "Manage Settings" (it uses mouse-hover, so if you don't see it move your mouse)
- Copy the id# from "Publisher ID: a14bfed196e8994"
- Create an account at AdWhirl. AdWhirl will act as aggregator, allowing you to mix-n-match ad hosting accounts (like AdMob).
- Under "Apps" click on "Add Application"
- Fill out the form. Make sure to choose 'Android'. Click "Add App"
- Note: At this point, I have seen an issue where it shows up on the screen twice. If I go into it and come back it resolves itself. Don't worry about it.
- Click on your new app's name
- Copy your SDK key from: "SDK Key:d34d05761f0544dab08b396807778d23"
- Next to AdMob, click on (mouse-hover again) "Edit Settings"
- Put the id# from above into the "PublisherID" box and apply it
- Under "Ad Serving" make sure AdMob is enabled
- Save Changes
- Download the latest Android zip from here. In this case, it is "AdWhirlSDK_Android_2.0.8.zip".
- Extract it to the disk somewhere and navigate to it from the command line
C:\java\AdWhirlSDK_Android_2.0.8> mvn install:install-file -Dfile=AdWhirlSDK_Android_2.0.8.jar -DgroupId=com.adwhirl -DartifactId=AdWhirlSDKAndroid -Dversion=2.0.8 -Dpackaging=jar
- Note: I took the version from the filename
Whew! Ok, with your accounts setup, let's create a basic project:
F:\work> mvn archetype:generate -DarchetypeCatalog=http://kallisti.eoti.org:8081/content/repositories/snapshots/archetype-catalog.xml
choose the galatea-archetype plugin
groupId: org.eoti.android
artifactId: AdWhirlTest
version: 1.0-SNAPSHOT
Assuming you have your emulator running...
F:\work> cd AdWhirlTest
F:\work\AdWhirlTest> mvn clean install
Add these dependencies to your pom.xml [change versions to match what you did earlier]:
<dependency>
<groupId>com.adwhirl</groupId>
<artifactId>AdWhirlSDKAndroid</artifactId>
<version>2.0.8</version>
</dependency>
<dependency>
<groupId>com.admob.android.ads</groupId>
<artifactId>AdMobAndroid</artifactId>
<version>20100331</version>
</dependency>
Add this to your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
Inside your src\main\android\res\layout\main.xml, insert this just above the bottom '</LinearLayout> '
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:id="@+id/layout_ad"
/>
Open your activity (src\main\java\org\eoti\android\AdWhirlTestActivity.java in my case)
Add this into the bottom of your onCreate method:
try{Note: Make sure to use the SDK Key from the AdWhirl setup earlier when creating the AdWhirlLayout.
AdManager.setTestDevices( new String[] { AdManager.TEST_EMULATOR } );
LinearLayout layout = (LinearLayout)findViewById(R.id.layout_ad);
AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this, "d34d05761f0544dab08b396807778d23");
Display d = this.getWindowManager().getDefaultDisplay();
RelativeLayout.LayoutParams adWhirlLayoutParams = new RelativeLayout.LayoutParams(d.getWidth(), 72);
layout.addView(adWhirlLayout, adWhirlLayoutParams);
}catch(Exception e){
Log.e(TAG, "Unable to create AdWhirlLayout", e);
}
Redeploy (mvn clean install) and launch it. You should see an ad at the bottom of the screen. If not, check your logs (you do have 'adb logcat' running, right?)