Android版使用移動廣告平臺集成Google Mobile Ads SDK教程

一:要求
1.請確保您使用的是最新版本的Android SDK,且編譯所針對的至少是Androidv3.2(將project.properties中的target設爲android-13)。
2.Google Mobile Ads SDK(Android版)要求使用Android 2.3或更高版本的運行時文件(在AndroidManifest.xml中至少將android:minSdkVersion設爲9)。這表示,您能夠使用最新版本的Android SDK進行開發,而您的應用仍能在更早版本的Android(最低2.3版)上運行。


二:加入SDK
將Google移動廣告加入應用是一個簡單的過程:
1.在您的Eclipse工做空間中添加和引用Google Play服務庫項目。
2.在AndroidManifest.xml中添加meta-data標記。
3.在清單中聲明com.Google.android.gms.ads.AdActivity。
4.在清單中設置網絡權限。


<1>添加和引用Google Play服務庫項目
a.在Eclipse中右鍵點擊您的應用項目,並選擇Properties。
b.選擇Android,而後點擊Add...。找到Google-play-services_lib項目,而後選擇OK以添加Google Play服務庫。
c.項目如今即會引用Google Play服務庫


<2>添加meta-data標記
Google Play服務要求您在應用的AndroidManifest.xml的元素內添加如下meta-data標記:
<?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>聲明com.Google.android.gms.ads.AdActivity
Mobile Ads SDK要求您在應用的AndroidManifest.xml中聲明com.Google.android.gms.ads.AdActivity

<?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>設置網絡權限
要建立廣告請求,必須在清單中聲明如下權限:INTERNET

用於訪問互聯網以發送廣告請求。ACCESS_NETWORK_STATE

KeyMob移動廣告平臺,簡稱「KeyMob廣告」,是爲開發者提供精準穩定的SDK,KeyMob平臺有橫幅廣告、插屏廣告、積分牆和視頻廣告等廣告形式,KeyMob平臺完美打造用戶體驗,鑄造開發者高收益!

android

相關文章
相關標籤/搜索