AdMobの設定

AndroidMarketにいきなり表示された「AdMob」の表示。
設定をして表示をする。

必要なもの

必要な設定

app
+ libs
   + admob-sdk-android.jar

AndroidManifest.xmlの「」の直前

<!-- The application's publisher ID assigned by AdMob -->
<meta-data android:value="パブリッシャー ID" android:name="ADMOB_PUBLISHER_ID" />
<!-- use a separate publisher id here to aid in tracking intersitial statistics -->
<meta-data android:value="パブリッシャー ID" android:name="ADMOB_INTERSTITIAL_PUBLISHER_ID" />
</application>

/res/values/attrs.xml

<?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>

AdMob広告を入れるレイアウトファイルにxmlnsとAdViewタグを追加する。
例)main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res/your.package.name"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    
    <com.admob.android.ads.AdView
        android:id="@+id/admob"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        myapp:backgroundColor="#000000"
        myapp:primaryTextColor="#FFFFFF"
        myapp:secondaryTextColor="#CCCCCC"
    />
</LinearLayout>

まとめ

  1. アカウント登録して,パブリッシャーIDをもらう。
  2. admob-sdk-android.jar を外部ライブラリとして配置,パスを通す。
  3. AndroidManifest.xmlの設定行追加。
  4. Viewに表示を追加。
  5. apkエキスポート。