Skip to main content

Installing Google AdMob into Android Apps

Previously I wrote on why ads are needed to help maintaining an app. Read the article here http://blog.kerul.net/2011/05/generating-revenue-from-free-mobile.html.

---This is quite an old article. You may find the latest supporting AdMob 6.x in here http://blog.kerul.net/2012/08/example-how-to-install-google-admob-6x.html ---

This is quite a long tutorial, there are 3 major steps involved. The experiment is done using Windows 7, Eclipse Helios and AdMob SDK 4.1.0 (which currently is the latest-during time of writing).

STEP 1: Get the ads from AdMob.com

To display the AdMob ads in your Android mobile apps, you need to register first at the admob.com . After completing the registration, login and Add Site/App. Refer to Figure 1.

image

Figure 1

Choose the desired platform and fill in the details (as in Figure 2). Just put http:// in the Android Package URL if your app is not published in the market yet. And click Continue.

ScreenHunter_16 May. 16 08.35

Figure 2

Download the AdMob Android SDK, and save the zip file in your machine. Make sure to extract the file and save it to your hard disk (anywhere is possible).

ScreenHunter_17 May. 16 08.36

Figure 3

STEP 2: Install the AdMob SDK into your Android project.

The most important file in the AdMob Android SDK that you download is GoogleAdMobAdsSdk-4.1.0.jar . Currently it’s in version 4.1.0 .

ScreenHunter_18 May. 16 08.40

Figure 4

Go to your project folder (in Eclipse), and right click to your project (Figure 5). Choose Properties.

image

Figure 5

Click the Java Build Path on your left. Choose the Libraries in the tab, and click Add External JARs. Locate the JAR file (GoogleAdMobAdsSdk-4.1.0.jar). And click OK.

image

Figure 6

image

Figure 7

image

Figure 8

STEP 3: The codes to display ads in your app.

Add some additional activity and permissions in the manifest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.android.calc"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Calc"
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"/>
<uses-sdk android:minSdkVersion="4" />

</manifest>


Create attr.xml file in the res/values 


 


 


Related links



  1. Official Documentation (which is not updated timely) - http://code.google.com/mobile/ads/docs/android/fundamentals.html
  2. Official Discussion (AdMob SDK 4.0.10) - http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/3b885d3fe5bb21a5?pli=1
  3. A very good tutorial for AdMob SDK 4.0.4 - http://android.jmsliu.com/209/add-google-admob-in-android-application.html?utm_source=rss&utm_medium=rss&utm_campaign=add-google-admob-in-android-application

Comments

  1. I think that attrs.xml file is not used anymore in version 4.1.0, so it's not needed. Also setTesting method is being deprecated.

    ReplyDelete
  2. Dear Anonymous,
    Thanks for the comment. I'll check and update this post later...

    ReplyDelete
  3. So far the hands-on provided here is working...

    ReplyDelete
  4. Hi,
    Can you take a look at the following question from stackoverflow.com ?

    http://stackoverflow.com/questions/5038158/main-activity-is-not-garbage-collected-after-destruction-because-it-is-referenced

    I seem to get this behavior ONLY when i load the AdView in my activity. Even an empty Activity with just the AdView widget takes tons of memory and I see with HPROF that what's keeping it from being released is that the InputMethodManager holds a reference to it (Which I didn't add anywhere...)

    ReplyDelete
  5. Another related question on the same memory issue:

    http://stackoverflow.com/questions/6148812/android-admob-causes-memory-leak

    ReplyDelete
  6. I've added the code and i'm not getting any add..
    I've changed ads:adUnitId="YOUR_PUBLISHER_ID_HERE" for ads:adUnitId="xxxxxxxxxxxxx" the x's stand for the Publisher Id.
    After waiting 4 minutes on my phone im not getting any ads?

    ReplyDelete
  7. Dear Christian,

    Maybe you could share with me the project folder, I'll check it for you.
    Email me at khirulnizam[a]gmail.com

    ReplyDelete
  8. I found that it's not working in the emulator. You need to test the admob ads in a real Android phone.

    ReplyDelete
  9. Try to add: adRequest.addTestDevice("314321C010A54CE800467089A3E155E6");
    Look for this code in LogCat while you start the app.

    ReplyDelete
  10. salam kenal sob, info: buat rekan2 yang ingin pasang mobgold/admob dengan java script di halaman html silahkan kunjungi http://wapads.idwap.net terimakasih

    ReplyDelete
  11. make sure to setTesting() to false, when you deploy the apps...

    AdView adview = (AdView)findViewById(R.id.adView1);
    AdRequest re = new AdRequest();
    re.setTesting(false);//this must be false when apps is released in the market
    adview.loadAd(re);

    ReplyDelete
  12. Can you tell me how to put an ads banner in the preview screen for a live wallpaper?As in the Fireflies live wallpaper (http://www.livewallpapers.org/fireflies-free-1543/), I don't know how to put an ads banner in the Preview screen (not Settings screen).

    When I install the Fireflies wallpaper on my HTC which is on Android 2.2.1 the banner shows up in both Preview and Settings screens, but on my two other Sony Ericsson (on 2.3.3) I can only see the banner in the Setting screens. Does that have something to do with Sony Ericsson or the version of Android?

    Thanks.

    ReplyDelete
  13. My app is telling me I need to have AdActivity declared in AndroidManifest with configChanges. but added the lines:

















    Any clue what is wrong?

    ReplyDelete
  14. ok so I found out that eclipse wants me to change to android:configChanges="keyboard|keyboardHidden|orientation|screenlayout|uiMode|screenSize|smallestScreenSize"/> but when I do this, it says string types not allowed.

    ReplyDelete
  15. Refer to this post for AdMob SDK 6.x http://blog.kerul.net/2012/08/example-how-to-install-google-admob-6x.html
    All the best...

    ReplyDelete
    Replies
    1. I have added this sample code to my app and it work perfect on my device, I saw my first admob ads for a brief moment in fact how many times evry time I run the app on my device but when it goes to the next activity it will not display the next screen and would totally kills the whole app. it say it stopped unexpectedly. can you help me. thanks.

      Delete
  16. also in addition i saw my admob status and shows that my app is sending my request. hence the code work but am i missing something an ondistroy or any class that would display the next activity I mean it totally just wont go to the next acctivity it displays the first screen with my admob insert running and it just crash evrytime it goes to the next screen. again thanks.

    ReplyDelete
  17. also in addition i saw my admob status and shows that my app is sending my request. hence the code work but am i missing something an ondistroy or any class that would display the next activity I mean it totally just wont go to the next acctivity it displays the first screen with my admob insert running and it just crash evrytime it goes to the next screen. again thanks.

    ReplyDelete
  18. sorry to add this again anyway, I have a fatal error: NoAPI database founf in null comment in my error log. I guess thats what it starts but how come it works when I dont have the admob insert. do I have to include something before going to the next activity. again sir thanks a million to your help.

    ReplyDelete
    Replies
    1. It's difficult for me to debug the error without having to look at the source code and the error message personally...

      Delete
    2. Wondering whether you install AdMob 4.x or AdMob 6.x...

      Delete

Post a Comment

Popular posts from this blog

Several English proverbs and the Malay pair

Or you could download here for the Malay proverbs app – https://play.google.com/store/apps/details?id=net.kerul.peribahasa English proverbs and the Malay pair Corpus Reference: Amir Muslim, 2009. Peribahasa dan ungkapan Inggeris-Melayu. DBP, Kuala Lumpur http://books.google.com.my/books/about/Peribahasa_dan_ungkapan_Inggeris_Melayu.html?id=bgwwQwAACAAJ CTRL+F to search Proverbs in English Definition in English Similar Malay Proverbs Definition in Malay 1 Where there is a country, there are people. A country must have people. Ada air adalah ikan. Ada negeri adalah rakyatnya. 2 Dry bread at home is better than roast meat home's the best hujan emas di negeri orang,hujan batu di negeri sendiri Betapa baik pun tempat orang, baik lagi tempat sendiri. 3 There's no accounting for tastes We can't assume that every people have a same feel Kepala sama hitam hati lain-lain. Dalam kehidupan ini, setiap insan berbeza cara, kesukaan, perangai, tabia

Enabling Intel Virtual Technology in LENOVO G50 - 80 BIOS setting

Turn off the laptop, and search for a SECRET BUTTON on the left side. Wait for the Lenovo logo to finish, and Choose BIOS setting. Go to CONFIGURATION tab, and you will see INTEL VIRTUAL TECHNOLOGY. Press ENTER on the VIRTUAL TECHNOLOGY option, and choose ENABLE. Fn+F10 to SAVE configuration and RESTART.

Contact Us at blog.kerul.net

Powered by EMF HTML Contact Form

The Challenges of Handling Proverbs in Malay-English Machine Translation – a research paper

*This paper was presented in the 14th International Conference on Translation 2013 ( http://ppa14atf.usm.my/ ). 27 – 29 August 2013, Universiti Sains Malaysia, Penang. The PDF version is here: www.scribd.com/doc/163669571/Khirulnizam-The-Challenges-of-Automated-Detection-and-Translation-of-Malay-Proverb The test data is here: http://www.scribd.com/doc/163669588/Test-Data-for-the-Research-Paper-the-Challenges-of-Handling-Proverbs-in-Malay-English-Machine-Translation Khirulnizam Abd Rahman, Faculty of Information Science & Technology, KUIS Abstract: Proverb is a unique feature of Malay language in which a message or advice is not communicated indirectly through metaphoric phrases. However, the use of proverb will cause confusion or misinterpretation if one does not familiar with the phrases since they cannot be translated literally. This paper will discuss the process of automated filtering of Malay proverb in Malay text. The next process is translation. In machine translatio

Most used STRING functions in my PHP coding

These are my favourite string manipulation functions in my daily coding life. Dedicated especially to Web Programming students. Read them and have fun. Expect a happiness after a storm , and you’ll find your “inner peace”… This post is still in draft. I’ll update and refine with more examples that I’ve personally develop. More after the break…