「Android Integeration with New AdMob Mediation 2.0」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
(取消由Wikiuser對話)所作出的修訂 511)
imported>Wikiuser
(取消由Wikiuser對話)所作出的修訂 510)
 
行 1: 行 1:
Mopub網站: https://app.mopub.com, 登入可對後台進行設定。<br>
*新版AdMob Mediation整合
: 請將擋廣告的插件關閉(如Adblock),否則後台瀏覽、設定會有問題<br><br>
新版AdMob網站, https://apps.admob.com, 登入後點選 "<b>營利</b>",
並點選將要新增"<b>廣告中介服務</b>"的應用程式<br/> [[File:android_22.png]]  ,<br/>
點選"<b>編輯中介服務</b>", 出現中介服務編輯畫面,選擇"<b>新增廣告聯播網</b>"<br/> [[檔案:android_23.png]]<br/>
再點選"<b>+自訂事件</b>"<br/>[[檔案:android_24.png]],<br/>  出現自訂事件設定畫面 <br/>[[檔案:android_25.png]],<br/>
依序填入
#Class Name : 請填入實作(implements <b>com.google.ads.mediation.customevent.CustomEventBanner</b>)的類別名稱(含完整的package name, 如<b>com.taiwanmobile.pt.adp.mediation.TAMediaBanner</b>)
# Label : TAMedia (任意自定的名稱)
# Parameter : 請填入您的TAMedia Slot Id (可向您的TAMedia窗口詢問),<br/>
完成後,按下左下角的"儲存",將自訂事件的內容儲存起來, 並回到應用程式管理畫面,[[檔案:android_26.png]]<br/>再按一次"儲存"將廣告中介服務的設定進行儲存


== Mopub後台設定 ==
::*整合至應用程式
<big><u>Step 1: 新增APP與版位,取得Mopub版位ID</u></big><br>
:::*Banner,依照下述方式將AdMob所提供的CustomEventBanner進行實作
進入Apps分頁後,點擊Add a New App<br>
  package com.taiwanmobile.pt.adp.mediation;
[[image:Mopub_Step1-1.png | 700px]]<br><br>
 
 
  import android.app.Activity;
輸入APP資訊,如APP Name、Package Name…等<br>
 
[[image:Mopub_Step1-2.png | 700px]]<br><br>
  import com.google.ads.AdRequest;
 
  import com.google.ads.AdSize;
新增版位並進行設定<br>
  import com.google.ads.mediation.MediationAdRequest;
:a. Format為橫幅廣告Banner (320x50):<br>
  import com.google.ads.mediation.customevent.CustomEventBanner;
[[image:Mopub_Step1-3.png | 700px]]<br><br>
  import com.google.ads.mediation.customevent.CustomEventBannerListener;
 
  import com.taiwanmobile.pt.adp.view.TWMAd;
:b. Format為插頁式廣告Fullscreen (320x480):<br>
  import com.taiwanmobile.pt.adp.view.TWMAdRequest;
[[image:Mopub_Step1-4.png | 700px]]<br><br>
  import com.taiwanmobile.pt.adp.view.TWMAdRequest.ErrorCode;
 
  import com.taiwanmobile.pt.adp.view.TWMAdSize;
:c. Format為原生廣告Native (Custom Layout):<br>
  import com.taiwanmobile.pt.adp.view.TWMAdView;
[[image:Mopub_Step1-5.png | 700px]]<br><br>
  import com.taiwanmobile.pt.adp.view.TWMAdViewListener;
 
  import com.taiwanmobile.pt.util.Log;
完成設定後,點選Save and View Code Integration,並記下Mopub的版位ID<br>
  // 需將本class的完整類別名稱 com.taiwanmobile.pt.adp.mediation.TAMediaBanner註冊於mediation的設定頁面上, 如前述章節所述
[[image:Mopub_Step1-6.png | 700px]]<br><br>
  public class TAMediaBanner implements CustomEventBanner {
[[image:Mopub_Step1-7.png | 700px]]<br><br>
 
 
  private static final String TAG = "TAMediaBanner";
若欲新增其他版位,請點選剛剛新增的APP並點選Add an Ad Unit<br>
 
[[image:Mopub_Step1-8.png | 700px]]<br><br>
  @Override
[[image:Mopub_Step1-9.png | 700px]]<br><br>
  public void destroy() {
<br>
 
<br>
  if(adView != null){
 
  adView.destroy();
<big><u>Step 2: 新增廣告聯播網</u></big><br>
  }
進入Network分頁,並點選Add a Network<br>
 
[[image:Mopub_Step2-1.png | 700px]]<br><br>
  }
 
 
點選Custom Native Network<br>
  //將AdMob所提供的MediationAdRequest轉換為TWMAdRequest
[[image:Mopub_Step2-2.png | 700px]]<br><br>
  private TWMAdRequest convertAdRequest(MediationAdRequest request) {
 
  TWMAdRequest adRequest = new TWMAdRequest();
設定Network Title(名字可任意取),並設定實作的類別名稱與參數,以下以Banner作為範例:<br>
  if (request.getBirthday() != null) {
[[image:Mopub_Step2-3.png | 700px]]<br><br>
  adRequest.setBirthday(request.getBirthday());
 
  }
依欄位填入<br>
  if (request.getAgeInYears() != null) {
<ol>
  adRequest.setAge(request.getAgeInYears());
<li>Custom Event Class: 用於實作com.mopub.mobileads.CustomEventBanner的類別名稱,必須輸入完整的package name,如com.taiwanmobile.pt.adp.mediation.TAMediaMopubBanner</li>
  }
<li>Custom Event Class Data: 請依指定格式輸入您的版位ID (可向您的TAMedia窗口詢問),格式為 {"adUnitId":"<版位ID>"}</li>
 
</ol>
  if (request.getGender() != null) {
輸入完畢後,後台會自動儲存<br>
  if (request.getGender().equals(AdRequest.Gender.FEMALE)) {
[[image:Mopub_Step2-4.png | 700px]]<br><br>
  adRequest.setGender(TWMAdRequest.Gender.FEMALE);
 
  } else if (request.getGender().equals(AdRequest.Gender.MALE)) {
最後進入Segment分頁,啟用方才設定的聯播網<br>
  adRequest.setGender(TWMAdRequest.Gender.MALE);
[[image:Mopub_Step2-5.png | 700px]]<br><br>
  } else {
 
  adRequest.setGender(TWMAdRequest.Gender.UNKNOWN);
若有多個聯播網,可透過eCPM調整不同聯播網的優先權<br>
  }
[[image:Mopub_Step2-6.png | 700px]]<br><br>
  }
<br>
 
<br>
  return adRequest;
 
  }
== Mopub程式整合 ==
 
<big><u>Step 1: Download TAMedia & Mopub SDK</u></big><br>
  //將AdMob的AdSize轉換為TWMAdSize
:a. 請參照 [https://github.com/mopub/mopub-android-sdk/wiki/Getting-Started#requirements-and-dependencies Mopub Github] 所提供的方式,將Mopub SDK加到您的專案中。<br>
  private TWMAdSize convertAdSize(AdSize adSize) {
:b. [[Download Android SDK 2 | Download TAMedia SDK]]<br><br>
  if(adSize.equals(AdSize.BANNER)){
 
  return TWMAdSize.BANNER;
<big><u>Step 2: 在AndroidManifest.xml加入所需的權限與Activity</u></big><br>
  }else if(adSize.equals(AdSize.IAB_BANNER)){
   &lt;!-- Mopub & TAMedia Permission --&gt;
  return TWMAdSize.IAB_BANNER;
   <uses-permission android:name="android.permission.INTERNET" />
  }else if(adSize.equals(AdSize.IAB_MRECT)){
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  return TWMAdSize.IAB_MRECT;
   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> &lt;!-- optional --&gt;
  }else if(adSize.equals(AdSize.IAB_LEADERBOARD)){
   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> &lt;!-- optional --&gt;<br>
  return TWMAdSize.IAB_LEADERBOARD;
   &lt;!-- TAMedia Permission --&gt;
  }else if(adSize.equals(AdSize.SMART_BANNER)){
   <uses-permission android:name="android.permission.READ_PHONE_STATE" /> &lt;!-- SDK4.0以上版本請移除 --&gt;
          return TWMAdSize.SMART_BANNER;
   <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  }else{
   <uses-permission android:name="android.permission.VIBRATE" /> &lt;!-- optional --&gt;
                        return TWMAdSize.BANNER;
   <uses-permission android:name="android.permission.CAMERA"/>  &lt;!-- optional, SDK4.0上請加入, 以獲得更豐富的廣告內容 --&gt;
  }
  <uses-permission android:name="android.permission.RECORD_AUDIO"/>  &lt;!-- optional, SDK4.0上請加入, 以獲得更豐富的廣告內容 --&gt;<br>
  }
   &lt;!-- Mopub Permission --&gt;
 
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 
 
  private TWMAdView adView = null;
   &lt;!-- TAMedia Activities --&gt;
 
   <activity
  @Override
  android:name="com.taiwanmobile.pt.adp.view.TWMAdActivity"
  public void requestBannerAd(final CustomEventBannerListener customListener, Activity activity,
   android:configChanges="orientation|keyboardHidden|navigation|keyboard|screenLayout|uiMode|screenSize|smallestScreenSize"
  String label, String serverParameter, AdSize adSize, MediationAdRequest request,
   android:hardwareAccelerated="true"
  Object extras) {
   android:theme="@android:style/Theme.Translucent" >
  Log.d(TAG, "requestBannerAd("+label+"/"+serverParameter+") invoked!!");
   </activity>
 
  adView = new TWMAdView(activity,convertAdSize(adSize),label);
 
  adView.setAdListener(new TWMAdViewListener(){
 
  @Override
  public void onReceiveAd(TWMAd ad) {
  customListener.onReceivedAd(adView);
 
  }
 
  @Override
  public void onFailedToReceiveAd(TWMAd ad, ErrorCode errorCode) {
  customListener.onFailedToReceiveAd();
 
  }
 
  @Override
  public void onPresentScreen(TWMAd ad) {
  customListener.onPresentScreen();
                                //若您需要在AdMob報表上觀察點擊率, 請加入CustomEventBannerListener.onClick()
                                customListener.onClick();
 
  }
 
  @Override
  public void onDismissScreen(TWMAd ad) {
  customListener.onDismissScreen();
 
  }
    
  @Override
  public void onLeaveApplication(TWMAd ad) {
  customListener.onLeaveApplication();
 
  }
 
  });
 
  adView.loadAd(convertAdRequest(request));
 
 
  }
    
  }
:::*Interstitial,依照下述方式將AdMob所提供的CustomEventInterstitial進行實作
  package com.taiwanmobile.pt.adp.mediation;
 
   import android.app.Activity;
 
   import com.google.ads.AdRequest;
  import com.google.ads.mediation.MediationAdRequest;
   import com.google.ads.mediation.customevent.CustomEventInterstitial;
  import com.google.ads.mediation.customevent.CustomEventInterstitialListener;
   import com.taiwanmobile.pt.adp.view.TWMAd;
  import com.taiwanmobile.pt.adp.view.TWMAdRequest;
   import com.taiwanmobile.pt.adp.view.TWMAdRequest.ErrorCode;
  import com.taiwanmobile.pt.adp.view.TWMAdViewListener;
   import com.taiwanmobile.pt.adp.view.TWMInterstitialAd;
  // 需將本class的完整類別名稱 com.taiwanmobile.pt.adp.mediation.TAMediaBanner註冊於mediation的設定頁面上, 如前述章節所述
   public class TAMediaInterstitial implements CustomEventInterstitial {
 
  // 將AdMob所提供的MediationAdRequest轉換為TWMAdRequest
  private TWMAdRequest convertAdRequest(MediationAdRequest request) {
  TWMAdRequest adRequest = new TWMAdRequest();
  if (request.getBirthday() != null) {
  adRequest.setBirthday(request.getBirthday());
  }
  if (request.getAgeInYears() != null) {
  adRequest.setAge(request.getAgeInYears());
  }
    
  if (request.getGender() != null) {
  if (request.getGender().equals(AdRequest.Gender.FEMALE)) {
  adRequest.setGender(TWMAdRequest.Gender.FEMALE);
  } else if (request.getGender().equals(AdRequest.Gender.MALE)) {
  adRequest.setGender(TWMAdRequest.Gender.MALE);
  } else {
  adRequest.setGender(TWMAdRequest.Gender.UNKNOWN);
  }
  }
    
  return adRequest;
  }
 
  @Override
  public void destroy() {
  // TODO Auto-generated method stub
 
  }
 
  private TWMInterstitialAd interstitialAd = null;
    
  @Override
  public void requestInterstitialAd(
  final CustomEventInterstitialListener customListener,
  Activity activity, String label, String serverParameter,
  MediationAdRequest request, Object extra) {
  interstitialAd = new TWMInterstitialAd(activity, serverParameter);
 
  interstitialAd.setAdListener(new TWMAdViewListener() {
 
  @Override
  public void onReceiveAd(TWMAd ad) {
  customListener.onReceivedAd();
 
  }
    
  @Override
  public void onFailedToReceiveAd(TWMAd ad, ErrorCode errorCode) {
  customListener.onFailedToReceiveAd();
 
  }
 
  @Override
  public void onPresentScreen(TWMAd ad) {
  customListener.onPresentScreen();
    
  }
 
  @Override
  public void onDismissScreen(TWMAd ad) {
  customListener.onDismissScreen();
 
  }
 
  @Override
  public void onLeaveApplication(TWMAd ad) {
  customListener.onLeaveApplication();
 
  }
 
  });
 
  interstitialAd.loadAd(convertAdRequest(request));
 
   }
 
   @Override
   public void showInterstitial() {
  if (interstitialAd != null) {
  interstitialAd.show();
  }
    
  }
    
    
   &lt;!-- Mopub activity --&gt;
   }
  <activity android:name="com.mopub.mobileads.MoPubActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
  <activity android:name="com.mopub.mobileads.MraidActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
  <activity android:name="com.mopub.common.MoPubBrowser" android:configChanges="keyboardHidden|orientation|screenSize"/>
  <activity android:name="com.mopub.mobileads.RewardedMraidActivity" android:configChanges="keyboardHidden|orientation|screenSize" />
  <activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
  <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />


  &lt;!-- Mopub meta-data --&gt;
::[[Download_Android_SDK_2|Download Android SDK and Sample]]
   <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
::加入必要的權限<br/>TWMAd服務需使用”存取網路狀態”、”讀取約略位置”、”網路”等權限,請在AndroidManifest.xml檔案當中進行下列權限的宣告。
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> &lt;!-- optional --&gt;
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> &lt;!-- optional --&gt;
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIRBATE" /> &lt;!-- optional --&gt;
::加入必要Activity
  &lt;!-- TAMedia Activities --&gt;
<activity
  android:name="com.taiwanmobile.pt.adp.view.TWMAdActivity"         
   android:configChanges="orientation|keyboardHidden|navigation|keyboard|screenLayout|uiMode|screenSize|smallestScreenSize"
  android:hardwareAccelerated="true"
  android:theme="@android:style/Theme.Translucent" >
</activity>
</activity>
&lt;!-- Google Play Service Activities --&gt;
<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" />
::在layout檔案中加入可放置廣告的LinearLayout(※僅供參考,開發者可依照自訂的layout進行配置使用)
<LinearLayout
android:id="@+id/Layout_AdView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
::在程式加入Ad的宣告
  public class MainActivity extends Activity {
  LinearLayout layout = null;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    layout = (LinearLayout) this.findViewById(R.id.Layout_AdView);
    adView = new AdView(this);
    adView.setAdUnitId("<Mediation ID>");
    adView.setAdSize(AdSize.BANNER);   
    layout.addView(adView);
    AdRequest request = new AdRequest.Builder().build();
    adView.loadAd(request);
  }
::*聯播網投放與維護
::當APP設定好Mediation並且發佈出去後,可直接透過Mediation網頁進行版位管理與聯播網比率調整,此設定會在1小時後生效。

於 2017年5月17日 (三) 09:25 的最新修訂

  • 新版AdMob Mediation整合

新版AdMob網站, https://apps.admob.com, 登入後點選 "營利", 並點選將要新增"廣告中介服務"的應用程式
Android 22.png ,
點選"編輯中介服務", 出現中介服務編輯畫面,選擇"新增廣告聯播網"
Android 23.png
再點選"+自訂事件"
Android 24.png,
出現自訂事件設定畫面
Android 25.png,
依序填入

  1. Class Name : 請填入實作(implements com.google.ads.mediation.customevent.CustomEventBanner)的類別名稱(含完整的package name, 如com.taiwanmobile.pt.adp.mediation.TAMediaBanner)
  2. Label : TAMedia (任意自定的名稱)
  3. Parameter : 請填入您的TAMedia Slot Id (可向您的TAMedia窗口詢問),

完成後,按下左下角的"儲存",將自訂事件的內容儲存起來, 並回到應用程式管理畫面,Android 26.png
再按一次"儲存"將廣告中介服務的設定進行儲存

  • 整合至應用程式
  • Banner,依照下述方式將AdMob所提供的CustomEventBanner進行實作
 package com.taiwanmobile.pt.adp.mediation;
 
 import android.app.Activity;
 
 import com.google.ads.AdRequest;
 import com.google.ads.AdSize;
 import com.google.ads.mediation.MediationAdRequest;
 import com.google.ads.mediation.customevent.CustomEventBanner;
 import com.google.ads.mediation.customevent.CustomEventBannerListener;
 import com.taiwanmobile.pt.adp.view.TWMAd;
 import com.taiwanmobile.pt.adp.view.TWMAdRequest;
 import com.taiwanmobile.pt.adp.view.TWMAdRequest.ErrorCode;
 import com.taiwanmobile.pt.adp.view.TWMAdSize;
 import com.taiwanmobile.pt.adp.view.TWMAdView;
 import com.taiwanmobile.pt.adp.view.TWMAdViewListener;
 import com.taiwanmobile.pt.util.Log;
 // 需將本class的完整類別名稱 com.taiwanmobile.pt.adp.mediation.TAMediaBanner註冊於mediation的設定頁面上, 如前述章節所述
 public class TAMediaBanner implements CustomEventBanner {
 	
 	private static final String TAG = "TAMediaBanner";
 
 	@Override
 	public void destroy() {
 		
 		if(adView != null){
 			adView.destroy();
 		}
 		
 	}
 	
 	//將AdMob所提供的MediationAdRequest轉換為TWMAdRequest
 	private TWMAdRequest convertAdRequest(MediationAdRequest request) {
 		TWMAdRequest adRequest = new TWMAdRequest();
 		if (request.getBirthday() != null) {
 			adRequest.setBirthday(request.getBirthday());
 		}
 		if (request.getAgeInYears() != null) {
 			adRequest.setAge(request.getAgeInYears());
 		}
 
 		if (request.getGender() != null) {
 			if (request.getGender().equals(AdRequest.Gender.FEMALE)) {
 				adRequest.setGender(TWMAdRequest.Gender.FEMALE);
 			} else if (request.getGender().equals(AdRequest.Gender.MALE)) {
 				adRequest.setGender(TWMAdRequest.Gender.MALE);
 			} else {
 				adRequest.setGender(TWMAdRequest.Gender.UNKNOWN);
 			}
 		}
 
 		return adRequest;
 	}
 	
 	//將AdMob的AdSize轉換為TWMAdSize
 	private TWMAdSize convertAdSize(AdSize adSize) {
 		if(adSize.equals(AdSize.BANNER)){
 			return TWMAdSize.BANNER;
 		}else if(adSize.equals(AdSize.IAB_BANNER)){
 			return TWMAdSize.IAB_BANNER;
 		}else if(adSize.equals(AdSize.IAB_MRECT)){
 			return TWMAdSize.IAB_MRECT;
 		}else if(adSize.equals(AdSize.IAB_LEADERBOARD)){
 			return TWMAdSize.IAB_LEADERBOARD;
 		}else if(adSize.equals(AdSize.SMART_BANNER)){
 		        return TWMAdSize.SMART_BANNER;
 		}else{
                       return TWMAdSize.BANNER;
 		}
 	}
 	
 	
 	private TWMAdView adView = null;
 
 	@Override
 	public void requestBannerAd(final CustomEventBannerListener customListener, Activity activity,
 			String label, String serverParameter, AdSize adSize, MediationAdRequest request,
 			Object extras) {
 		Log.d(TAG, "requestBannerAd("+label+"/"+serverParameter+") invoked!!");
 		
 		adView = new TWMAdView(activity,convertAdSize(adSize),label);
 		
 		adView.setAdListener(new TWMAdViewListener(){
 
 			@Override
 			public void onReceiveAd(TWMAd ad) {
 				customListener.onReceivedAd(adView);
 				
 			}
 
 			@Override
 			public void onFailedToReceiveAd(TWMAd ad, ErrorCode errorCode) {
 				customListener.onFailedToReceiveAd();
 				
 			}
 
 			@Override
 			public void onPresentScreen(TWMAd ad) {
 				customListener.onPresentScreen();
                               //若您需要在AdMob報表上觀察點擊率, 請加入CustomEventBannerListener.onClick()
                               customListener.onClick();
 				
 			}
 
 			@Override
 			public void onDismissScreen(TWMAd ad) {
 				customListener.onDismissScreen();
 				
 			}
 
 			@Override
 			public void onLeaveApplication(TWMAd ad) {
 				customListener.onLeaveApplication();
 				
 			}
 			
 		});
 		
 		adView.loadAd(convertAdRequest(request));
 		
 		
 	}
 
 }
  • Interstitial,依照下述方式將AdMob所提供的CustomEventInterstitial進行實作
 package com.taiwanmobile.pt.adp.mediation;
 
 import android.app.Activity;
 
 import com.google.ads.AdRequest;
 import com.google.ads.mediation.MediationAdRequest;
 import com.google.ads.mediation.customevent.CustomEventInterstitial;
 import com.google.ads.mediation.customevent.CustomEventInterstitialListener;
 import com.taiwanmobile.pt.adp.view.TWMAd;
 import com.taiwanmobile.pt.adp.view.TWMAdRequest;
 import com.taiwanmobile.pt.adp.view.TWMAdRequest.ErrorCode;
 import com.taiwanmobile.pt.adp.view.TWMAdViewListener;
 import com.taiwanmobile.pt.adp.view.TWMInterstitialAd;
 // 需將本class的完整類別名稱 com.taiwanmobile.pt.adp.mediation.TAMediaBanner註冊於mediation的設定頁面上, 如前述章節所述
 public class TAMediaInterstitial implements CustomEventInterstitial {
 
 	// 將AdMob所提供的MediationAdRequest轉換為TWMAdRequest
 	private TWMAdRequest convertAdRequest(MediationAdRequest request) {
 		TWMAdRequest adRequest = new TWMAdRequest();
 		if (request.getBirthday() != null) {
 			adRequest.setBirthday(request.getBirthday());
 		}
 		if (request.getAgeInYears() != null) {
 			adRequest.setAge(request.getAgeInYears());
 		}
 
 		if (request.getGender() != null) {
 			if (request.getGender().equals(AdRequest.Gender.FEMALE)) {
 				adRequest.setGender(TWMAdRequest.Gender.FEMALE);
 			} else if (request.getGender().equals(AdRequest.Gender.MALE)) {
 				adRequest.setGender(TWMAdRequest.Gender.MALE);
 			} else {
 				adRequest.setGender(TWMAdRequest.Gender.UNKNOWN);
 			}
 		}
 
 		return adRequest;
 	}
 
 	@Override
 	public void destroy() {
 		// TODO Auto-generated method stub
 
 	}
 
 	private TWMInterstitialAd interstitialAd = null;
 
 	@Override
 	public void requestInterstitialAd(
 			final CustomEventInterstitialListener customListener,
 			Activity activity, String label, String serverParameter,
 			MediationAdRequest request, Object extra) {
 		interstitialAd = new TWMInterstitialAd(activity, serverParameter);
 
 		interstitialAd.setAdListener(new TWMAdViewListener() {
 
 			@Override
 			public void onReceiveAd(TWMAd ad) {
 				customListener.onReceivedAd();
 
 			}
 
 			@Override
 			public void onFailedToReceiveAd(TWMAd ad, ErrorCode errorCode) {
 				customListener.onFailedToReceiveAd();
 
 			}
 
 			@Override
 			public void onPresentScreen(TWMAd ad) {
 				customListener.onPresentScreen();
 
 			}
 
 			@Override
 			public void onDismissScreen(TWMAd ad) {
 				customListener.onDismissScreen();
 
 			}
 
 			@Override
 			public void onLeaveApplication(TWMAd ad) {
 				customListener.onLeaveApplication();
 
 			}
 
 		});
 
 		interstitialAd.loadAd(convertAdRequest(request));
 
 	}
 
 	@Override
 	public void showInterstitial() {
 		if (interstitialAd != null) {
 			interstitialAd.show();
 		}
 
 	}
 
 }
Download Android SDK and Sample
加入必要的權限
TWMAd服務需使用”存取網路狀態”、”讀取約略位置”、”網路”等權限,請在AndroidManifest.xml檔案當中進行下列權限的宣告。
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!-- optional -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- optional -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.VIRBATE" /> <!-- optional -->
加入必要Activity
<!-- TAMedia Activities -->
<activity
 android:name="com.taiwanmobile.pt.adp.view.TWMAdActivity"           
 android:configChanges="orientation|keyboardHidden|navigation|keyboard|screenLayout|uiMode|screenSize|smallestScreenSize"
 android:hardwareAccelerated="true"
 android:theme="@android:style/Theme.Translucent" >
</activity>
</activity>
<!-- Google Play Service Activities -->
<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" />
在layout檔案中加入可放置廣告的LinearLayout(※僅供參考,開發者可依照自訂的layout進行配置使用)
<LinearLayout
android:id="@+id/Layout_AdView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
在程式加入Ad的宣告
 public class MainActivity extends Activity {
  LinearLayout layout = null;
  @Override
  public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   layout = (LinearLayout) this.findViewById(R.id.Layout_AdView);
   adView = new AdView(this);
   adView.setAdUnitId("<Mediation ID>");
   adView.setAdSize(AdSize.BANNER);    
   layout.addView(adView);
   AdRequest request = new AdRequest.Builder().build();
   adView.loadAd(request);
  }
  • 聯播網投放與維護
當APP設定好Mediation並且發佈出去後,可直接透過Mediation網頁進行版位管理與聯播網比率調整,此設定會在1小時後生效。