アプリ開発備忘録

PlayStationMobile、Android、UWPの開発備忘録

[Android]AdMob導入

Android クイック スタート  |  AdMob Android ガイド  |  Google Developers
これの内容をSDKのDLなどを省いた内容です。

build.gradle

compile 'com.google.android.gms:play-services:6.+'


AndroidManifest.xml

//manifest内
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

//application内
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />


テスト広告ID

ca-app-pub-3940256099942544/6300978111


AdView設置

xmlns:ads="http://schemas.android.com/apk/res-auto"

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>


AdView読み込み

AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);


広告タイプ

バナー広告のカスタマイズ  |  AdMob Android ガイド  |  Google Developers