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应用开发中,嵌入广告是常见的盈利方式之一,尤其对于免费应用来说。"youmi-android-sdk-v3.05_2011-12-30" 是一个针对Android平台的优米(Youmi)广告SDK,用于帮助开发者在他们的应用程序中集成广告展示...
【标题】:“自己挣点油钱__AdMob:在Android应用中嵌入广告的方案” 在Android应用开发中,为了实现盈利或者补贴开发成本,许多开发者会选择在自己的应用中嵌入广告。AdMob是Google提供的一个强大的移动广告平台,...
公司可以自主研发 Android 应用,嵌入广告,借助免费的 API 及开源代码快速集成应用,紧跟消费市场需求和 Android 版本更新速度,可以定位一些应用研发,一方面培养 Android 研发团队,一方面沉淀 Android 技术,...
本文将详细介绍如何在Android应用中嵌入AdMob广告。 #### 二、准备工作 1. **注册AdMob账号** 首先,需要访问AdMob官方网站并完成注册。登录后,找到“站点和应用程序”选项卡。 2. **添加新应用** 在“站点...
【AdviewSDK_Android-master】是一个专门为Android平台设计的广告SDK项目,它的核心目标是为开发者提供集成广告网络的功能,从而在应用中嵌入不同类型的广告,如横幅广告、插屏广告、视频广告等。这个SDK使得开发者...
在Android应用开发中,"嵌入广告位定时显示"是一个重要的功能设计,它涉及到广告的高效管理和用户体验的优化。此功能允许开发者在特定的时间点显示广告,而不是无时无刻都展示,这样既能保证广告的有效传播,又不会...
在Android应用开发中,将广告集成到应用中是常见的盈利方式之一,AdView SDK就是这样的一个工具,它允许开发者在应用程序中嵌入广告,从而实现收益。本文将深入讲解AdView SDK在Android App中的使用方法及其相关知识...
- **简介**:通过在应用内部嵌入广告来获得收入,是最常见的盈利方式之一。 - **优点**:易于实施,对于用户而言接受度较高。 - **缺点**:可能会影响用户体验,尤其是弹窗广告等较为侵扰的形式。 - **应用场景*...
在Android应用开发中,有时需要将广告嵌入到软件界面以获取收益或推广。这篇文档主要介绍了如何在Android应用中嵌入有米广告的详细步骤。有米广告是一家提供移动广告解决方案的公司,其SDK可以帮助开发者轻松地在...
它为开发者提供了在Android应用程序中集成广告的能力,从而实现流量变现。本文将深入探讨AppOffer SDK的特性、使用方法以及其在广告投放中的优势。 一、AppOffer SDK概述 AppOffer SDK是一款专为Android平台设计的...
在Android平台上,接入穿山甲广告(Tencent X5)是一项常见的任务,它能帮助开发者在应用程序中嵌入各种类型的广告,如横幅广告、全屏广告和激励视频广告,从而实现流量变现。本文将详细讲解如何使用Cocos2d-x游戏...
有米广告平台为Android开发者提供了一套完善的广告嵌入解决方案,通过集成其SDK(Software Development Kit),开发者可以在自己的应用中轻松实现广告展示功能。本文将详细介绍如何在Android应用中集成并使用有米...
3. **移动广告**:在应用中嵌入广告插件,通过展示广告来获取收入。 4. **搭建平台(软件商店)**:创建自己的应用分发平台,通过抽取应用销售收入的一定比例作为收益来源。 5. **撰写书籍**:针对Android开发的专业...
- **广告**:这是最常见的盈利模式之一,通过在应用内部嵌入广告来获得收入。 - **付费应用**:用户需支付一定费用才能下载或使用该应用。 - **虚拟商品**:许多游戏或社交类应用会提供虚拟商品供用户购买,以此获利...
2. **广告适配器**:在Android中,广告通常以Adapter的形式嵌入到ListView或RecyclerView等视图中。源码中的适配器类会解析广告数据并将其转化为可视化的视图组件。 3. **用户交互处理**:当用户点击广告或进行其他...
这些库通过提供一个运行Flash内容的沙箱环境,使得开发者可以将Flash内容嵌入到Android应用中。需要注意的是,使用这样的库可能需要用户在设备上安装额外的组件,且可能不支持所有Android版本或设备。 在源码分析...
本教程主要针对初学者,旨在帮助他们理解和掌握如何在Android应用中集成和使用Google服务。 首先,我们要了解Google Play服务(Google Play Services)。这是一个后台服务,它不断更新,提供了与Google API交互的库...
近年来,随着Android系统的普及,针对该平台的恶意应用也在不断增加,导致用户面临着各种各样的手机问题,这些问题包括但不限于待机耗电过快、无缘故的流量超标、APP异常崩溃、手机发烫以及广告骚扰等。这些问题的...
万普广告是一款在移动应用开发中广泛使用的广告平台,它为开发者提供了丰富的广告形式和高效的变现途径。在本文中,我们将深入探讨万普广告的原理、功能以及如何通过集成其SDK来实现应用内的广告展示。 首先,让...
相较于原生Android Webview,该插件具有更好的集成性和性能优化,使得开发者能轻松地在Unity应用中嵌入网页内容。 Unity作为一个强大的跨平台游戏开发工具,广泛应用于游戏开发、互动媒体和虚拟现实应用等领域。...