AdMob是一个比较成熟的移动平台 广告 商,其为android 和 iphone提供了非常方便的集成JAR包,使得开发 者可以在自己的应用 中很方便的嵌入其提供的广告 ,进而按照广告 展 示和点击次数付广告 费。这里用个例子 给大家演示下如何在自己的应用中集成AdMob的广告 功能 。
0、准备工作
去http://www.admob.com/ 注 册一个帐号,然后添加一个“Add Mobile Site”,输入相关信息后,提交完成,进入AD代码 获取 界面 ,其提供了PHP,Rails等等类型的代码,同时 提供了Android平台使用的JAR,我们就来演示这个。
1、下载 JAR包
其为android 平台提供了JAR包,然后将JAR添 加到你的项目 组,按照如下步骤
- 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、编辑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 like a14a48e3387c5ce . Just before the closing </app lication> tag add a line to set your publisher ID:
1
2
3
4
5
6
7
8
9
10
|
<!-- 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 letting 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、添加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:
1
2
3
4
5
6
7
8
9
10
11
|
<?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 includes your package name specified in AndroidManifest.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<?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.eoe android .demo.Adadmob"
android :orientation="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 - 最棒的Android开发社区 " />
<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 立足于Android开发者 ,营造一个乐于分享、共同进步的开发者社区." />
<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>
|
原文链接:http://yangguangfu.javaeye.com/blog/675502
分享到:
相关推荐
如何为自己的android应用嵌入广告。
android 自定义键盘,在页面嵌入的。使用还算简单
如何在Android应用中嵌入 AdMob 广告,里面有个文档和一个 AdmobDemo
在 Android 项目中添加 libcocos2dx 依赖模板,首先需要在 `File` 菜单中选择 `New` > `Import Module`,然后选择 CocosCreator 项目中的 `cocos2d-x\cocos\platform\android\java` 目录下的 `libcocos2dx` 模板。...
在android应用程序中嵌入v8引擎的演示应用程序
Android程序中嵌入百度移动联盟广告,写的一个很简单的demo,广告横屏显示应用底部
android程序员们,你们想知道怎样再android中嵌入广告呢,让我们的程序生活得到保证呢,嵌入广告是一个不错的选择,这里提供了一些关于怎样在程序中嵌入广告!
基于DWT-DCT-SVD算法的音频水印嵌入和提取算法MATLAB仿真
行业分类-物理装置-一种嵌入IT应用系统中的规则中心.zip
安卓条码扫描库,ZXing解码。
Android 项目中嵌入 ReactNative
适合刚接触android学习的初学者,在android应用中嵌入广告,欢迎朋友们下载。
原代码 博文链接:https://yangguangfu.iteye.com/blog/675502
OLE-2-对象链接与嵌入技术高级编程技术pdf版。学习哦了的好资料。
TongWeb-k8s部署运行TongWeb嵌入版应用--示例文件
MMA中国无线营销联盟移动互联网App应用嵌入广告SDK监测标准
使用cocos2dx新建的helloword工程,嵌入到android原生项目中的demo
Android程序中嵌入百度移动联盟广告.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
W-SVD模型下水印的嵌入算法源代码、相应的检测算法源代码(MATLAB中实现的)