Search Tutorials

Sunday, 29 December 2013

Add Google AdMob Ads in Android Application & Earn Money

Want to Earn Money from Android Application? Yes, than you are on right place to get accurate method to earn money via android application. AdMob is the best mobile advertising site/company to fill your pocket in dollars. Initially, i don't have any idea to earn money via android apps but now i know how can i earn money from my android applications that's why I am sharing this method and hope everyone like it.

In this Tutorial, we will learn how to show Google AdMob Ads on Android Application step by step. We will need the following two things:-

1. Ad Unit Id from Admob site.
2. Google Play Services installed in Android SDK.

How to get Ad Unit Id from Admob site:-

1. Go to Admob site.

2. Create New Account (if you are already an admob user, then log in). 

3. Select "Monetize new app" option.

Admob monetize new app

4. Search your app on Google play or fill details manually of your app to connect.

Form to add app on Admob site

5. After filling all information, you will get instruction to set up admob unit id.

7. Now you have added your app to admob site. Go to Monetize tab and check your added app in "all app" list and than select your added app and create new ad-unit. Create ad-unit for banner or Interstitial Ads as you want in your application and get Ad Unit id which will look like this: ca-app-pub-xxxx71439079xxxx/270233xxxx.

8. Now use Ad Unit Id in your project.

How to get Google Play Services Folder:-

1. Open android SDK -> Click on Windows -> android SDK manager -> extras -> download Google play services.

Add Google AdMob Ads in Android Application
Install Google Play Service Packages

After installing Google Play services, import it in your workspace as an android project. Now we have Admob Ad Unit Id and Google play services both. Create a new project to test Ads on android application and use Google play services as a library in your android project.

How to Add Google AdSense code in Android Application:-

1. Now select project -> right click on project -> properties -> android -> add library -> select Google play services folder -> Apply.

How to add Google AdMob Ads in Android Application
Add Google Play Services Package As a Library

2. Open your android XML file and add the following line in layout:

xmlns:ads=http://schemas.android.com/apk/res-auto

3. Add AdView in Layout:

<com.google.android.gms.ads.AdView
 android:id="@+id/adView"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 ads:adSize="BANNER"
 ads:adUnitId="YOUR_AD_UNIT_ID"
/> 

4. The Android XML file will look like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:ads="http://schemas.android.com/apk/res-auto"
 android:id="@+id/mainLayout"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
>
<com.google.android.gms.ads.AdView
 android:id="@+id/adView"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentBottom="true"
 android:layout_alignParentLeft="true"
 ads:adSize="BANNER"
 ads:adUnitId="Your_AD_UNIT_ID"
/>
</RelativeLayout>

5. Now open your Java file and initialize AdView Object in your Activity.

AdView ad=(AdView)findViewById(R.id.adView);

6. Load Ad from Google:

ad.loadAd(new AdRequest.Builder().build());

Now change AndroidManifest.xml file according to the code given in the end of the tutorial & run your project. Now install the application on your phone & check ads!

For Interstitial Ads:-

This Ad will be displayed on your complete phone screen.

1. Use the following code in your activity:

 InterstitialAd end_ad=new InterstitialAd(this);
    end_ad.setAdUnitId(getResources().getString(Your_AD_UNIT_ID));
    end_ad.loadAd(new AdRequest.Builder().build());

2. Show Ad if loaded:

if(end_ad.isLoaded())
          {
             end_ad.show();
          }

Now change AndroidManifest.xml file according to the code given in the end of the tutorial & run your project. Now install the application on your phone & check ads!

Now change AndroidManifest.xml file:

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

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />

<!-- Used to request banner and interstitial ads. -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- Used to avoid sending an ad request if there is no connectivity. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
 android:allowBackup="true"
 android:icon="@drawable/ic_launcher"
 android:label="@string/app_name"
 android:theme="@style/AppTheme">

<meta-data
 android:name="com.google.android.gms.version"
 android:value="@integer/google_play_services_version" />

<activity
 android:name="com.example.Main_Activity"
 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 required to show ad overlays. -->
<activity
 android:name="com.google.android.gms.ads.AdActivity"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>

Both above examples are used in the following Android applications: Helper+ & Namaz Guide

Mostly apps use Admob Ads in Listview and show Ads when Loaded. Initially, I was confused that how can I add Ads after successfully loading and finally I got success and felt it was very easy. I added AdView widget at bottom of the parent layout & set visibility gone and use Listview widget in whole layout. After setting up XML file, I used below code in Activity:-

ad=(AdView)findViewById(R.id.adView);
ad.setVisibility(View.GONE);
ad.loadAd(new AdRequest.Builder().build());

ad.setAdListener(new AdListener() {
 @Override
 public void onAdLoaded() {
  ad.setVisibility(View.VISIBLE);
 }
});

Related Tutorials:-

Display Time using Broadcast Receiver in Android

Check Battery level using Broadcast Receiver in Android

Display all Mobile Contacts in Android

Perform Action on any Hardware Button in Android

How to Add Facebook SDK in Android Application

63 comments:

  1. Can you please give details on how to add Admob interstitial ads to an android BuzzTouch v3 project? I mean how and where exactly do I put those codes in my BT project in eclipse?

    ReplyDelete
    Replies
    1. I didn't make application on buzzTouch but i made two android applications which are mentioned above. I am using interstitial ads on first page on back button. when user open application ad will start to load and after opening application, user can visit other pages of the application. At the end user go back and want to close application using back button at that time if interstitial ad has loaded successfully than ad will open in full page and use flag to show it once time & if user click back button again than application will close.
      Note: No need to use XML code for interstitial ads, just define it in Java and show it when you want.

      Delete
    2. So how and where do I define it?

      Delete
    3. Use the below code in your Activity:

      InterstitialAd end_ad=new InterstitialAd(this); end_ad.setAdUnitId(getResources().getString(“Your_AD_UNIT_ID”));
      end_ad.loadAd(new AdRequest.Builder().build());

      And show Ads when you want like on any button click or without any button click..using below code:

      if(end_ad.isLoaded())
      {
      end_ad.show();
      }

      And don't forgot to change AndroidManifast.xml file and to replace YOUR_AD_UNIT_ID with your id or use my id for example: a152c80c278af19

      Delete
    4. Thanks for your quick responses, Only the banner ads work fine for me now. You see I am new in android app development.

      Can you please show me an example java code with the above Interstitial code in it? I don't know how to place the above interstitial code in java.

      Delete
    5. Create New Android Project and do nothing in XML files & open Your Java File and paste below code in oncreate(Bundle obj) method:

      InterstitialAd end_ad=new InterstitialAd(this); end_ad.setAdUnitId("a152c80c278af19");
      end_ad.loadAd(new AdRequest.Builder().build());
      if(end_ad.isLoaded())
      {
      end_ad.show();
      }

      Now open your AndroidManifest.xml file and change according to above given AndroidManifast.xml: give Internet access & permission, use meta tag and define Google activity.

      Now save and run & install apk file in your mobile. Open Internet connection and open application and wait for a moment, you will see Ad.

      Thanks for comment bro and if you like my work please share it.

      Delete
    6. I am showing some part of my android project to help you(See it, it will help you):

      public class MainActivity extends Activity {
      TextView tv=null;
      SQLiteDatabase db;
      AutoCompleteTextView et=null;
      String[] arr;
      private InterstitialAd end_ad=null;
      boolean flag=false;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      tv=(TextView)findViewById(R.id.textView1);
      et=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
      db=openOrCreateDatabase("freelance", MODE_PRIVATE, null);
      db.execSQL("create table if not exists mytable(name1 varchar,name2 varchar,name3 varchar)");
      end_ad=new InterstitialAd(this);
      end_ad.setAdUnitId(getResources().getString(R.string.ad_unit_id));
      end_ad.loadAd(new AdRequest.Builder().build());
      end_ad.show();
      if(end_ad.isLoaded())
      {
      tv.setText("Ad loaded");
      }

      }

      @Override
      public void onBackPressed()
      {
      if(flag==false && end_ad.isLoaded())
      {
      end_ad.show();
      flag=true;
      }
      else
      {
      finish();
      }
      }
      }

      Delete
    7. when I add the above code to any of my app screen, it crashes that particular screen.

      Delete
    8. Give me your email id, i will send you complete project in rar file. Extract File and import in SDK than Add Google play services package as a library(as mentioned in post) and run. Install Apk file in mobile and wait for a moment to display Ads.

      Delete
    9. The problem is that BuzzTouch uses Fragment and not Activity as explained in the above code, can you please add Admob Interstitial ads using BuzzTouch sample code?

      Delete
    10. I didn't try BuzzTouch for making Application, So can't give any example...sorry.

      Delete
    11. I have Solved it Here:

      https://www.buzztouch.com/forum/thread.php?tid=64DE8F7C56FC178B149FAFB

      Delete
    12. Congrats...good work. :)

      Delete
    13. Please send me apk tool admob sir,i am wonkjasenk79@gmail.com thanks

      Delete
  2. Is the process same for adding adfonic id instead admob

    ReplyDelete
    Replies
    1. I never tried adfonic ads but i know this works with google adsense id and admob id. You have to read instructions and visit developer site of adfonic.

      Delete
  3. Nice information. Thank you sir..

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Use Google Admob..it is best and don't believe any others sites because they might be pay or not.

      Delete
  5. Hey guys can u help me on how to add banner in android eclipse its not working on me :(

    ReplyDelete
    Replies
    1. Already given on this post..just chat me on hangout to resolve problem.

      Delete
  6. Hi
    When I goto admob.com it redirects to https://www.google.com/ads/admob/. I can't find Sites and Apps option. Please help.

    ReplyDelete
    Replies
    1. Oh AdMob change website and look..use it you will get easily to add code.

      Delete
  7. hi i made a quiz application and integrated intersitial ads in it but app is crashing without internet if we open with internet when u click before ad loaded app is crashing but if we wait for ad after displaying ad app is working fine plz help me to resolve it

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. I am having heap space error after adding google play library could you please help me?

    ReplyDelete
    Replies
    1. hi ..
      open your eclipse folder > open eclipse.txt file >
      after this put the values in your file
      -Dhelp.lucene.tokenizer=standard
      -Xms512m
      -Xmx1024m

      after save and restart your eclipse.
      enjoy

      Delete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. hey this is very good tutorial , its work for me. thanks.

    ReplyDelete
  12. I have an apk file downloded from a web site.
    Can i get money on uploading to admob.

    ReplyDelete
  13. how can i get the source and what changes should be made to upload to admob

    ReplyDelete
  14. Nice work sir .i will try this code .if any query i will ask you .reply for my query .thank you sir

    ReplyDelete
  15. A/a.it is showing me:"The method getString(int) in the type Resources is not applicable for the arguments (String)",plz reply where is mistake

    ReplyDelete
  16. at this:end_ad.setAdUnitId(getResources().getString(""));

    ReplyDelete
    Replies
    1. please add your Ad Id in setAdUnitId("your_ad_id") method.

      Delete
  17. HI
    I am not able to display banner ads can you please help me by sending me the instuction or the souce file emailid- devanshchaudhary2002@gmail.com

    ReplyDelete
  18. HI
    I am not able to display banner ads can you please help me by sending me the instuction or the souce file. Can we add on android applications developed by appypie.com. emailid- qazilko@gmail.com

    ReplyDelete
    Replies
    1. Hi, yes you can add it in application developed by appypie.com and for instruction you can go through above tutorial.

      Delete
    2. I have done it. Now i wish to get FCM Service on my Appypie App. I mean to say data message notification service like facebook, whatsApp, Gmail etc. Is it possible on appypie App?

      Delete
  19. Hi, Please can I change the admob ad code in an App with another code, and if I can were would I go too

    ReplyDelete
  20. How do i add my admob banner to my APK file? I am unable to imported into android studio and that is where i am stucked. Please help

    ReplyDelete
  21. How do i add my admob banner to my APK file? I am unable to imported into android studio and that is where i am stucked. Please help

    ReplyDelete
  22. assalam alaikum
    send me your complete project in rar file
    my email id is
    rmdnizam@gmail.com

    ReplyDelete
  23. I have done it. Now i wish to get FCM Service on my Appypie App. I mean to say data message notification service like facebook, whatsApp, Gmail etc. Is it possible on appypie App?

    ReplyDelete
    Replies
    1. I have left job from AppyPie Inc. Now you have to ask this on AppyPie website.

      Delete
  24. Hi there, I found your blog via Google while searching for such kinda informative post and your post looks very interesting for me.writers have great importance in the writing company because they are the ones who solve customer's problems with respect to their needs. write my essay

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. Your unique method made it easier for me to understand it.In some mechanically pushed nations the young people are to an extraordinary degree on this page sharp and perky and exploiting their enlightening employments in school, school and in the school.

    ReplyDelete
  27. Anonymous11:47 pm

    More recently, I spent almost all my time studying lessons and homework. In my dreams of vacationing somewhere on the sea, I spent hours writing an essay I hate. But more recently, everything has changed thanks to help with writing the dissertation . Now I am lying on the islands in the sun and I am glad that there is a resource, gives so much free time!

    ReplyDelete
  28. I really wanted to type a small note so as to appreciate you for the superb guides you are sharing on this site. My time-consuming internet research has now been compensated with really good facts and techniques to exchange with my good friends. I would claim that most of us visitors are definitely endowed to exist in a fabulous website with many awesome people with very helpful pointers. I feel really happy to have seen your entire website and look forward to really more enjoyable minutes reading here. Thanks again for a lot of things. Singapore SEO

    ReplyDelete
  29. I'm truly enjoying the design and layout of your blog. It's a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a designer to create your theme? Superb work! website design

    ReplyDelete
  30. I like the valuable info you provide on your articles. I will bookmark your blog and test again right here frequently. I am fairly certain I will be informed lots of new stuff proper right here! Best of luck for the following! important online marketing strategy

    ReplyDelete
  31. Hey, your article is really great. This is very informative for me. Thank you very much for sharing the fascinating information with us. At ABAssignmentHelp, we generally work hard to reach out to the Assignment Help Services according to the measures and principles students receive in the best assessment. We are providing the best writing services at an affordable price.

    ReplyDelete
  32. Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! However, how could we communicate?
    printing company singapore

    ReplyDelete
  33. I carry on listening to the rumor talk about getting boundless online grant applications so I have been looking around for the finest site to get one. Could you tell me please, where could i acquire some?
    travel insurance singapore

    ReplyDelete
  34. Hey would you mind letting me know which webhost you're utilizing? I've loaded your blog in 3 completely different internet browsers and I must say this blog loads a lot quicker then most. Can you recommend a good internet hosting provider at a reasonable price? Kudos, I appreciate it! search engine marketing agency

    ReplyDelete
  35. It’s actually a cool and helpful piece of info. I’m glad that you shared this helpful information with us. Please keep us informed like this. Thanks for sharing. website development singapore

    ReplyDelete
  36. Good day! Would you mind if I share your blog with my twitter group? There's a lot of people that I think would really appreciate your content. Please let me know. Online marketing

    ReplyDelete
  37. The other day, while I was at work, my sister stole my iphone and tested to see if it can survive a 40 foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is totally off topic but I had to share it with someone!
    What questions should I ask a web designer?

    ReplyDelete
  38. hello sir, i'm new in app development, can you help me for develop a android app? actually i want to monetize a app with add.
    Plz help me.

    ReplyDelete
  39. It’s really a great and useful piece of information. I’m glad that you shared this useful info with us. Please keep us informed like this. Thank you for sharing.
    marketing company singapore

    ReplyDelete

Back to Top