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
    • 686
    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) : com.google.android.gms:play-services:6.+
      your dependencies will resemble like this:
      dependencies {
              compile fileTree(dir: 'libs', include: ['*.jar'])
              compile 'com.android.support:appcompat-v7:21.0.0'
              compile 'com.google.android.gms:play-services:6.+'
          }
      + 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:
        <meta-data 
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"/>
      • And finally include AdActivity into you manifest:
        <activity android:name="com.google.android.gms.ads.AdActivity" 
        android:configchanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode| screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />

    4. Add an xml layout : fragment_ad.xml :
      
      <relativelayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:ads="http://schemas.android.com/apk/res-auto"
      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_centerHorizontal="true" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" </com.google.android.gms.ads.AdView>
      </relativelayout>
    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 {
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
               Bundle savedInstanceState) {
              return inflater.inflate(R.layout.fragment_ad, container, false);
          }
      
      @Override
      public void onActivityCreated(Bundle bundle) {
          super.onActivityCreated(bundle);
          AdView mAdView = (AdView) getView().findViewById(R.id.adView);
          AdRequest adRequest = new AdRequest.Builder().build();
          mAdView.loadAd(adRequest);
      }
      }
      
    7. Add this fragment wherever you want to show your add in the activity and in android:name attribute write the path to AdFragment.
      <fragment
      android:id="@+id/adFragment"
      android:name="add.the.path.to.AdFragment.class"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>
    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 : https://www.google.com/admob/
      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
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
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: