You are here

Chapter 09: Connect to AdMob

As I mentioned earlier, I want to show ads in JustRoids. My ad-broker of choice is AdMob.

I have opened up an account on: http://www.admob.com/ with my contact details and my bank account number.

It won't be any large amount of money pouring in from AdMob for displaying ads - you'll get a few cents for each click on an ad-banner. But if the volumes are large enough...

Anyway, when you're registered on AdMob, visit: http://www.admob.com/my_sites/create_site and click on "Android App":

Enter your apps name and the package name you choose when you created your Eclipse project. Once again - don't pick the same as I did:

Click on "Download AdMob Android SDK". It's an archive containing a file that needs to be included in your Eclipse project:

Click on "Go to Sites/Apps", and select "Manage Settings" for your app:

You will now get to see your Publisher ID. Write this down somewhere, as you will use it in you Eclipse project soon. 

Click on the "App Settings" tab:

Check "Google Ads: Use Google Ads..." and click "Save Settings":

 

Now it's time to locate the "AdMob Android SDK" archive we just downloaded and unpack it. It should contain the following:

Copy the jar file (or the whole folder) into your home folder, Dev folder or similar.

Now go back to Eclipse, mark your new project, right click on it and select "Properties":

Select "Java Build Path" and "Add External JARs...":

Find the AdMob Android SDK jar file, verify that it is included in the list and click "OK":

Now expand your project tree in the Package Explorer, double-click on "AndroidManifest.xml" and click the rightmost tab (AndroidManifest.xml) to open up the file in a text editor:

Here we must add one new "activity" and two new "uses-permission":

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ajomannen.justroids"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.permission.INTERNET"/>    
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".JustRoidsActivity"
            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|screenLayout|uiMode|screenSize|smallestScreenSize"
        />
    </application>
</manifest>

Actually I became stuck here for a while when I tried to add the "android:configChanges" line. All seven of the listed allowed configuration changes needs to be included, just as in the code above, but almost half of them was not valid parameters until Android 3.2. This means that my intended target Android version (2.1) does not support them...

I found my way around the problem by changing the target version for a while by right-clicking "JustRoids" in the Eclipse Package Explorer, select "Properties", "Android", "Project Build Target" and select the latest Android version (4.0.3 - API Level 15) instead of 2.1 (API Level 7):

I kept the line <uses-sdk android:minSdkVersion="7" /> in the manifest file, though, and cross my fingers that it won't cause any conflicts.

 

After saving our manifest file, the foundation for displaying AdMob ads is in place!

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer