8.24.2014

Add google-play-services_lib project

Add google-play-services_lib project 

1. 在 Android SDK Manager 中,確認 Extras -> Google Play service 已安裝.

2. 由Eclipse 進行 project import:File -> Import -> Android -> Existing Android Code Into Workspace -> 挑選 google-play-services_lib 的位置 (ex: /develope/Lib/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib),記得選擇libproject 裡的資料夾.

3. 在原本的 project 設定:Eclipse -> Project ->Properties -> Android -> Library -> Add -> 挑選 google-play-services_lib.




條件
1. 請確認您使用的是最新版的 Android SDK,並依據 Android v3.2 或更新版本進行編譯 (將 project.properties 中的 target 設為 android-13)。

2. Android 專用 Google Mobile Ads SDK 要求 Android 2.3 或更新版本 (將 AndroidManifest.xml 中的 android:minSdkVersion 至少設為 9) 的執行階段。也就是說,您可以使用最新版本的 Android SDK 進行開發,而您的應用程式仍然可以在較早的 Android 版本 (至少 2.3 版) 上運作。


整合 SDK
將 Google 行動廣告整合進應用程式相當簡單:

1. 在 Eclipse 工作區中新增並參照 Google Play 服務程式庫專案。
2. 在 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。
<?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
                 選用。用來在發出廣告請求前,先行檢查是否有可用的網路連結。


【Reference】
https://developers.google.com/mobile-ads-sdk/docs/

No comments:

Post a Comment