Add admob advertisement for Google Play Service

1. Add and reference the Google Play services library project

a. Right click on your app project in Eclipse and select
Properties.

b. Select
Android
and then click Add.... Find the   google-play-services_lib project and select
OK to add the  Google Play services library.

c. The project now references the Google Play services library.

2. Add a meta-data tag

Google Play services requires you to add the following meta-data tag within the
element in your app‘s AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.company"
          android:versionCode="1" android:versionName="1.0">
  <application android:icon="@drawable/icon" android:label="@string/app_name"
               android:debuggable="true">
    <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version"/>
    <activity android:label="@string/app_name" android:name="BannerExample">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>
  </application>
</manifest>

3. Declare com.google.android.gms.ads.AdActivity

The Mobile Ads SDK requires that com.google.android.gms.ads.AdActivity be declared in your app‘s
AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.company"
          android:versionCode="1" android:versionName="1.0">
  <application android:icon="@drawable/icon" android:label="@string/app_name"
               android:debuggable="true">
    <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version"/>
    <activity android:label="@string/app_name" android:name="BannerExample">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>
    <activity android:name="com.google.android.gms.ads.AdActivity"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
  </application>
</manifest>

4. Set up network permissions

Making ad requests requires these permissions to be declared in the manifest:

INTERNET
Required. Used to access the Internet to make ad  requests.
ACCESS_NETWORK_STATE
Optional. Used to check if an internet connection is  available prior to making an ad request.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.company"
          android:versionCode="1" android:versionName="1.0">
  <application android:icon="@drawable/icon" android:label="@string/app_name"
               android:debuggable="true">
    <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version"/>
    <activity android:label="@string/app_name" android:name="BannerExample">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>
    <activity android:name="com.google.android.gms.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
  </application>
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>

5. Defining a com.google.android.gms.ads.AdView

The easiest way to incorporate an ad is to simply define your
AdView as you would any other part of your res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
  <com.google.android.gms.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"/>
</LinearLayout>

As usual you must replace MY_AD_UNIT_ID with your AdMob ad unit ID. Note the inclusion of the
ads namespace referenced in specifying adUnitId and
adSize
.

6. Look up and Load

To fetch ads, look up the AdView as a resource via
findViewById, create an AdRequest, and invoke loadAd:

import com.google.android.gms.ads.*;

public class BannerExample extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Look up the AdView as a resource and load a request.
    AdView adView = (AdView)this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);
  }
}

Add admob advertisement for Google Play Service

时间: 2024-10-05 19:40:15

Add admob advertisement for Google Play Service的相关文章

add Admob with Cocos2d-x on iOS

add Admob with Cocos2d-x on iOS (2013-02-27 14:12:00) 转载▼ 标签: c=blog&q=it&by=tag" target="_blank" style="text-decoration:none; color:rgb(62,115,160); white-space:nowrap">it   1. download admob, setup your account 2. add

how to add borders for a google map marker 谷歌地图 自定义图钉

If you are not satisfied with default Google map Marker (Default google marker can only be a icon, image or shape), for example adding a border, then you should use richmarker! http://google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker

Genymotion安装Google Play Service

作为一个Android开发者,如果你还不知道Genymotion,那么你一定是一个初学者. 众所周知,Genymotion的运行效率秒杀Google提供的模拟器N多条皇后大道,所以Genymotion成为了当前全球最火热,最流行的Android模拟器.笔者发此文时,最细版本已经到了2.6.0. Genymotion索然十分易用和快速,但是Genymotion却默认不包含Google Play Store,Google Maps这样的Google服务.最近笔者遇一个基于Google Service

小米google play service停止工作解决办法,不root,不刷第三方recovery(也适用于其他的手机)

问题: 原因是手机安卓系统是6.0.系统应用里面没有包含谷歌框架等一系列谷歌的小东西. 参考: http://www.miui.com/thread-3548436-1-1.html http://www.miui.com/thread-3132679-1-1.html 然后我既不想root(因为谷歌安装器好像可以解决不过需要root).也不想刷第三方的recovery(用来刷入包含谷歌各种服务的包). www.hisoma.com/364.html http://mytiankong.com/

ios Google play service接入步骤

首先按照: https://developers.google.com/games/services/ iOS start guide说明 建立应用和其他步骤 在console中可以建立app https://console.developers.google.com/project/ 之后需要在 https://play.google.com/apps/publish/ 中配置好工程,填入bundleid和其他信息,重要*要加入测试账号,不然会导致app的未发布状态下去测试会一直无法login

how to add borders for a google map marker 谷歌地图 自己定义图钉

If you are not satisfied with default Google map Marker (Default google marker can only be a icon, image or shape), for example adding a border, then you should use richmarker! http://google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker

cocos2dx加Admob不显示的解决方法

cocos2dx2.2.3按照官方文档加入Admod.启动应用在eclipse日志显示“Ad finished loading”,但是界面中不显示广告, 只有通过锁屏后重新点亮屏幕时能够显示. 经过Google解决方案如下 1 adView.loadAd(adRequest); 2 adView.setBackgroundColor(Color.BLACK); 3 addContentView(adView,adParams); 4 adView.setBackgroundColor(0); 另

Google 地图 API for Android

原文:Introduction to Google Maps API for Android 作者:Eunice Obugyei 译者:kmyhy 从健康类 app Runkeeper 到游戏 app 精灵宝可梦,位置服务对现代 app 来说越来越重要. 在本文中,我们将创建一个 app,名字就叫做 City Guide.这个 app 允许用户搜索一个地点,使用 Google 地图显示这个地点的位置并监听用户的位置改变. 我们将学习如何使用 Google 地图 API for Android,G

【青椒原创】2016C#模拟谷歌Google登陆Gmail&amp;Youtube小案例

之所以写这个,是因为本来想写一个Youtube刷评论的工具,把登录做出来了,后面就没继续做下去. 涉及到基本的HttpWatch的应用以及Fiddler的应用(Fd主要用来排查问题,通过对比 浏览器和vs代码 找出问题所在!以浏览器为标准). 通过HttpWatch抓包分析,我把登录Youtube一共分为三个阶段: 1. 请求 打开录入邮箱地址 页面 2. 请求 回发本邮箱地址,加载邮箱账号 头像 3. 请求 回发本邮箱地址和密码, 登录Youtube 有很多的Cookie和PostData的话