Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Monetize your Application by adding Ad banners in your android application

    • 0
    • 3
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 889
    Comment on it

    Adding ad banners into you app
    To monetize your app you can add advertisements and earn revenues based on viewers visiting the ads. You'll see below how easily you can add advertisement banners through Admob.
    Admobs is a Google acquired company and is one of the largest advertisement platforms with over 40 billion advertisement banners. It offers monetizing and promotion of your app. Admobs support many mobile platforms like android, IOS, webOS, Flash Lite, Windows Phone and all standard mobile browsers.
    This is the best practices to show your ads. follow the steps given below- In your Android studio project :

    1. Download google repository in your SDK which is present in the extras section.
    2. Add dependency into Application level build.gradle file (There is a project level and a application level build.gradle file) :
      your dependencies will resemble like this:
      dependencies {
              compile fileTree(dir: 'libs', include: ['*.jar'])
              compile ''
              compile ''
      + sign indicates the most recent version available that has a version number starting with 6 .
    3. Add these lines into your manifest file

      • In your manifest attribute add these two permissions:
        <uses-permission android:name="android.permission.INTERNET">
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
      • In the application attribute add this metadata tag:
      • And finally include AdActivity into you manifest:
        <activity android:name="" 
        android:configchanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode| screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />

    4. Add an xml layout : fragment_ad.xml :
      android:layout_height="match_parent"> < android:id="@+id/adView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" </>
    5. Add this into your string.xml file :

      <string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
      This a default ad unit id for testing purposes.If you already have the advertisement id,you can replace with that. This ID enables you to organise and monitor ads which are displayed to users.

    6. Create a fragment:
      public static class AdFragment extends Fragment {
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
               Bundle savedInstanceState) {
              return inflater.inflate(R.layout.fragment_ad, container, false);
      public void onActivityCreated(Bundle bundle) {
          AdView mAdView = (AdView) getView().findViewById(;
          AdRequest adRequest = new AdRequest.Builder().build();
    7. Add this fragment wherever you want to show your add in the activity and in android:name attribute write the path to AdFragment.
    8. Run the application.

      Now,you've given a default ad unit id and the revenue can not be generated . You've to create account in the AdMob website and generate a advertisement id in order to monetize your app.

    9. Generating Advertisement id

      1. If you don't have the account you need to sign up. To sign up, go to this link :
      2. Now click on Monetize new App and follow the instructions . They will ask your project or aplication name . And you can customize the advertisement type as per your needs . Finally, a new ad unit id will be generated . Replace the value of the string banner_ad_unit_id with that value.
      3. Run the application again. And you can analyse your ad views in your AdMob account.

 1 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: