hyoromoのブログ

最近はVRSNS向けに作ったものについて書いています

Admob設定方法

自分用メモ。コピペでいけるように書いてるつもり。Admob自体の初期設定に関しては他のサイトを参照ください。

配信アプリケーションのサイト上での設定

  1. Admob公式サイトのmy site上にある「サイト/アプリケーションの追加」をクリック。
  2. Androidアプリケーションを選択。
  3. App名、AndroidMarketのURL名、ジャンル、アプリ説明を書きます。
  4. 遷移先のページは無視して、再度my sitesに戻ります。
  5. 今回作ったアプリ名が一覧に表示されるので、「設定を管理」をクリック。
  • パブリッシャー IDが表示されるので、これを覚えておいてください。

アプリ側への設定

AndroidManifest設定

以下のコードをapplicationタグ内に追加。パブリッシャー IDは先ほど覚えた物を使用する。

<manifest>
    <application>
         ・・・省略・・・

        <activity
            android:name="com.admob.android.ads.AdMobActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:configChanges="orientation|keyboard|keyboardHidden"
        ></activity>

        <!-- Track Market installs from AdMob ads -->
        <receiver android:name="com.admob.android.ads.analytics.InstallReceiver" android:exported="true">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>

        <!-- 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>
</manifest>
attrs設定

attrs.xmlをres/valuesに追加*1。中身は以下のようにする。

<?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を表示させるLayout設定

以下のコードは、webviewで表示させている下にAdmob広告を表示させる例です。
重要なのは、LinearLayoutタグ内に書いたxmlns:appと、com.admob.android.ads.AdViewタグです。xmlns:appのパッケージ名だけ置き換えれば、他コピペでOK。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/アプリケーションパッケージ名"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
>
    <WebView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content
	android:layout_weight="1"
    ></WebView>
    <com.admob.android.ads.AdView
        android:id="@+id/ad"
        android:layout_width="fill_parent" 
        android:layout_height="48dp"
        app:backgroundColor="#000000"
        app:primaryTextColor="#FFFFFF"
        app:secondaryTextColor="#CCCCCC"
    ></com.admob.android.ads.AdView>
</LinearLayout>

確認方法

広告が表示される画面を表示し、広告が表示されればOK。されなければ設定を見直してください。
広告が表示された後、Admobのmy sitesを表示すると、今回作成したアプリ行のステータスがアクティブ*2になっていると思います。
これで配信可能状態となりましたので、このままAndroidMarket上に配信ください。

*1:他の言語対応していても、そこには入れない

*2:赤から緑色になってる