010-06-02AdMob: advertisement embedding solution in android applications-[mobile development]
Copyright Disclaimer: During reprinting, please use hyperlinks to indicate the original source and author information of the article and this statement
Http://cjbskysea.blogbus.com/logs/64953528.html
AdMob is a mature mobile platform Advertiser. It provides a very convenient JAR package for android and iphone, allowing developers to easily embed the ads they provide in their own applications, then, the advertising fee is charged based on the number of AD presentations and clicks.
Example: how to integrate AdMob's advertisement function in your own applications
Go to http://www.admob.com/register an account, and then click "add Mobile Site". After Entering the relevant information, submit the information. Go to the AD code acquisition page, which provides PHP, Rails, and other types of code, and the JAR used by the Android platform, this is demonstrated here.
1. Download the JAR package
It provides a JAR package for the android platform and then adds the JAR package to your project team. follow these steps:
- Go to the Properties of your project (right-click on your project from the Package Explorer tab and select Properties)
- Select "Java Build Path" from left panel
- Select "Libraries" tab from the main window
- Click on "Add JARs ..."
- Select the JAR copied to the libs directory
- Click "OK" to add the SDK to your android project
2. Edit AndroidManifest. xml
Your AdMob publisher ID was given to you when creating your publisher account on www.admob.com before downloading this code. It is a 15-character code likeA14a48e3387c5ce. Just before the closing </application> tag add a line to set your publisher ID:
<! -- The application's publisher ID assigned by AdMob -->
<Meta-data android: value = "YOUR_ID_HERE" android: name = "ADMOB_PUBLISHER_ID"/>
</Application>
Set any permissions not already included just before the closing </manifest> tag:
<! -- AdMob SDK permissions -->
<Uses-permission android: name = "android. permission. INTERNET"/>
<Uses-permission android: name = "android. permission. READ_PHONE_STATE"/>
<Uses-permission android: name = "android. permission. ACCESS_COARSE_LOCATION"/>
</Manifest>
Only the INTERNET permission is required. setting READ_PHONE_STATE is highly recommended because it identifies the user leader a greater variety of more relevant ads be chosen. finally setting ACCESS_COARSE_LOCATION (and/or ACCESS_FINE_LOCATION) will let geo-targeted ads be shown.
3. Add attrs. xml
The attrs. xml file specifies custom AdView attributes in XML layout files. if your application does not already have an/res/values/attrs. xml file then create one and copy-and-paste the following into it. if you do have that file then just add the declare-styleable element:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Declare-styleable name = "com. admob. android. ads. AdView">
<Attr name = "testing" format = "boolean"/>
<Attr name = "backgroundColor" format = "color"/>
<Attr name = "textColor" format = "color"/>
<Attr name = "keywords" format = "string"/>
<Attr name = "refreshInterval" format = "integer"/>
<Attr name = "isGoneWithoutAd" format = "boolean"/>
</Declare-styleable>
</Resources>
4. Placing an AdView in a Layout
AdView widgets can be put into any XML layout now. The first step is to reference attrs. xml in your layout element by adding an xmlns line that contains des your package name specified in AndroidManifest. xml:
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout
Xmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: admobsdk = "http://schemas.android.com/apk/res/com.eoeandroid.demo.Adadmob"
Androidrientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: textSize = "24px"
Android: paddingBottom = "10px"
Android: layout_gravity = "center"
Android: text = "eoeAndroid-the best Android development community"/>
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: textSize = "18px"
Android: paddingBottom = "10px"
Android: layout_gravity = "center"
Android: text = "eoeAndroid.com is based on Android Developers to create a developer community that is willing to share and make progress together."/>
<Com. admob. android. ads. AdView android: id = "@ + id/ad"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Admobsdk: backgroundColor = "#000000"
Admobsdk: textColor = "# FFFFFF"
Admobsdk: keywords = "Android application"
Admobsdk: refreshInterval = "60"
/>
</LinearLayout