Android Wing of mucchin | AdMob related



How to display and how to configure the application to the Android AdMob ads


How to how to set the AdMob advertising Android app, to be displayed is?

AdMob will be a sequel to related articles so far.
"AdMob" how to get advertising revenue in the Android app
How to Register for AdMob advertising revenue to be obtained in the Android app
How to download apps to Android SDK registration and AdMob

This time, as previous articles in the above, as you have completed registration and Android applications you want to advertise to AdMob, to download the AdMob SDK, how to set up or how to display ads AdMob Android app to the next stage of This section describes.


Basically, if you think and look at javadoc of Android AdMob SDK, a PDF file, and can be set.
It is a document written in English, was able to set the PDF file, but I look somehow.
The following steps, we will set the ads to Android app.

Import of AdMob SDK

First of all, the project of Android apps want to advertise on, or import a jar file of Android AdMob SDK.
There is a previous article, I wrote how to import the jar file, see the following articles, please import the admob-sdk-android.jar.
how to import the library that is provided in the jar file

And PDF of the AdMob SDK documentation and javadoc, but the difference is subtle procedure, the same thing.


Android Manifest file editing

Following, Android Manifest file to (AndroidManifest.xml), to describe the (publisher ID) publisher ID.
Open the AndroidManifest.xml.
This is not only to write the XML directly, if you open the manifest file in Eclipse, please select the tab called "AndroidManifest.xml".
Please look for that are described in the manifest file, the following parts.

</ Application>

Just above that line, please add the following.

<meta-data android:name="ADMOB_PUBLISHER_ID" android:value="xxxxxxxxxxxxx"/>

To "xxxxxxxxxxxxx" above, to describe the publisher ID of Android apps you have registered to AdMob.
This is the ID that is assigned one to each application.
Finding Publisher ID is
Log in to AdMob, go to the page of "sites and applications."
Then, at the bottom, you will find a list of Android apps you have registered.
When you press the button "manage settings" of Android apps you want to examine a Publisher ID, such as the following screen will be displayed.
How to display and how to configure the application to the Android AdMob ads
Have put in the red part of the above mosaic, Publisher ID has been described.
Part has put in black mosaic, application name is displayed the way.


Add Permission

Android apps you want to advertise on AdMob, and then grant the following permissions.
Android.permission.INTERNET: Required
Android.permission.ACCESS_COARSE_LOCATION: any
Android.permission.ACCESS_FINE_LOCATION: any
How to set permissions, please see the following article.
How to set up (Permission) permission in Eclipse

And that any permission, right? Relationship LOCATION.
I think you have enabled this permission, of ads AdMob is appropriate depending on the position information is displayed so (apparently), and some is not it a good idea to take effect if there is no problem.


Add attrs.xml

Android apps you'd like to advertise AdMob, the directory of / res / values ​​/, then add the XML that attrs.xml.
To add an XML, please refer to the following articles.
How to add XML in Eclipse
(. To select the "Values" in step 4 of the article above)

Then, the contents of the XML, do the following.


<? Xml version = "1.0" encoding = "utf-8"?>
<resources>
<declare-styleable name="com.admob.android.ads.AdView">
<attr name="backgroundColor" format="color" />
<attr name="primaryTextColor" format="color" />
<attr name="secondaryTextColor" format="color" />
<attr name="keywords" format="string" />
<attr name="refreshInterval" format="integer" />
</ Declare-styleable>
</ Resources>


If it already exists attrs.xml if you need to add new is not available.
If so, please add the tag and its child elements declare-styleable above.




Adding AdMob ads into the layout

Well, to Android apps finally, add the ads AdMob.
Open the XML file of the layout you want to display the ads AdMob.
Open the tab that is not an, "layout" tab If you open the layout XML in Eclipse, then edit the XML directly.
I think a line like the following, and at the very beginning.
xmlns: android = "http://schemas.android.com/apk/res/android"
Below this, add the following lines.
xmlns: myapp = "http://schemas.android.com/apk/res/ jp.mucchin.xxxxx"
In bold above, you write a package of Android apps you want to advertise.
Please be careful when spelling mistake here, the compilation does not pass later!
I stumbled here, I would use the time ... wasted.

Then, add the View of ads AdMob.
Procedure is similar to adding the MapView of Google Map.
Where you want to add, and then write the following.


<Com.admob.android.ads.AdView
android: id = "@ + id / ad"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
myapp: backgroundColor = "# 000000"
myapp: primaryTextColor = "# FFFFFF"
myapp: secondaryTextColor = "# CCCCCC" />


Test mode of AdMob ads

In the previous step, set of ads AdMob is complete for now.
But, by and from the emulator is, that there is no ad to display, you may AdMob ad is not displayed properly.
So, in test mode, and then try to test the display ads.
Of Activity to display the ads AdMob, onCreate per () method, please call the following line.


AdManager.setTestDevices (new String [] {
AdManager.TEST_EMULATOR,
});


Test mode is now enabled.
The following screen will be displayed.
How to display and how to configure the application to the Android AdMob ads

If you have a look at the logs in the LogCat, log out and you should have a "AdMob Test Android Web Ad".

Also, if you set up the layout of multiple ads AdMob, Android app at startup, I'll only run once the above code, the ads in the app that is all I want to be in test mode.
So, every Activity, need to put the above code is not available.


To test, if you are satisfied with the layout and display position of advertising AdMob, comment out the code above, you are done.
Although I commented out, even if started in the emulator, and is not to see any ads AdMob, if it was a log of the following, is not only out from there are no ads to display, and it is operating normally .
"Server replied that no ads are available"


View of ads such as position and color, position and color, it means appropriate, I think it varies from app.
After that, actually exposes the Android application, etc. to verify the click rate, and to validate various, the most appropriate position and color, let's aim to reward up!

2 3 4 A four page one of two 3 four