Monetize your Android Application with AdMob
Submitted by pavel7_7_7 on Tuesday, September 2, 2014 - 09:15.
In one of the last tutorials I wrote about the process of developing an Android version of Tic-Tac-Toe game.
Everyone has a wish to get a profit from his Android Application. In this tutorial you will find information about how to integrate an AdMob banner in your application in EclipseIDE.
The first step to monetize your application is to import google_play_services_lib into your Workspace. For this scope you need make an import of existing project from the location: "adt-location"\sdk\extras\google
If you make a correct import, you will find a new project in your Workspace, called google_play_services_lib.
The next step is to reference the google_play_services_lib in your project. For this scope, right-click on your project -> Properties -> Android. Here you can find Add button. Press it and add google_play_services_lib reference to your project.
Now your IDE is set correct and the next step is to sign in AdMob. The process of registration is quite simple, so I think, there is no need to describe it.
After you log in your account, press Monetize tab in the top of the page.
On this page press Monetize new app button. There you can add your application by searching in Google Play, iTunes App Store if you app was publiched. Or you can add your app manually by entering it's name.
After entering your application name you need to set your banner settings. I did it in the following way:
The registration of new banner is finished. New information will be displayed. You need to remember ad unit ID for this banner:
To use the AdMob ads in yourapplication you need to add this meta-data to the AndroidManifest.xml file inside application tag:
add permission to use Internet before application tag:
and add an activity:
Now we can add the banner directly to the application. There are 2 ways of adding a banner to your project - using xml or in your Activity class.
I'll add the banner with the xml code.
Fot this scope, the first thing that should be done is adding a namespace for AdMob ads in the root element of your layout. Open activity_normal.xml from the Tic-Tac-Toe layouts folder and add this line to the root element:
Now you can add the AdMob banner to your application. We can add it in the bottom of the application's screen after
Replace the MY_AD_UNIT_ID with the id you received after the creating of a new banner.
Another important thing for you banner is to set test devices. You must always do it , because it will enable test mode for your emulators and devices. If you want to test your app on a real device you must add this code to the
The device ID can be found in LogCat during you start your application on a real device.
That all and now we can test our banner:
The source code of the project is attached. There few modification to the version from the last project. So you can check everything directly here.
- <meta-data android:name="com.google.android.gms.version"
- android:value="@integer/google_play_services_version"/>
- <uses-permission android:name="android.permission.INTERNET" />
- <activity android:name="com.google.android.gms.ads.AdActivity"
- android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
- xmlns:ads="http://schemas.android.com/apk/res-auto"
TableLayout
element:
- <com.google.android.gms.ads.AdView android:id="@+id/banner" android:layout_alignParentBottom="true"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- ads:adUnitId="MY_AD_UNIT_ID"
- ads:adSize="SMART_BANNER"/>
protected void onCreate(Bundle savedInstanceState)
method:
- AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
- adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
- adRequestBuilder.addTestDevice("device id");
- AdView adView = (AdView)findViewById(R.id.banner);
- adView.loadAd(adRequestBuilder.build());
- }
Add new comment
- 3157 views