「Android Mopub Interstitial」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
(新頁面: 請建立一個Class並繼承Mopub所提供的CustomEventInterstitial<br><br> Class實作內容如下:<br> package com.taiwanmobile.pt.adp.mediation; import android.app.Activi...)
 
imported>Wikiuser
 
(未顯示同一使用者於中間所作的 7 次修訂)
行 16: 行 16:
   import java.util.Map;
   import java.util.Map;
    
    
   // 需將本class的完整類別名稱 com.taiwanmobile.pt.adp.mediation.TAMediaMopubInterstitial 填入後台的Custom Event Class欄位
   '''// 需將本class的完整類別名稱 com.taiwanmobile.pt.adp.mediation.TAMediaMopubInterstitial 填入後台的Custom Event Class欄位'''
   public class TAMediaMopubInterstitial extends CustomEventInterstitial {
   public class TAMediaMopubInterstitial extends CustomEventInterstitial {
       private static final String TAG = "TAMediaInterstitial";
       private static final String TAG = "TAMediaInterstitial";
行 32: 行 32:
           mInterstitialListener = customEventInterstitialListener;
           mInterstitialListener = customEventInterstitialListener;
    
    
           String adUnitId = serverExtras.get("adUnitId");
           String adUnitId = serverExtras.get("adUnitId"); '''//後台設定的adUnitId會透過此Key值取得'''
           interstitialAd = new TWMInterstitialAd( (Activity)context, adUnitId );
           interstitialAd = new TWMInterstitialAd( (Activity)context, adUnitId );
           interstitialAd.setAdListener(new TWMAdViewListener(){
           interstitialAd.setAdListener(new TWMAdViewListener(){
               @Override
               @Override
               public void onReceiveAd(TWMAd ad) {
               public void onReceiveAd(TWMAd ad) {
                   mInterstitialListener.onInterstitialLoaded();
                   if(mInterstitialListener != null)
                      mInterstitialListener.onInterstitialLoaded();
               }
               }
    
    
               @Override
               @Override
               public void onFailedToReceiveAd(TWMAd ad, TWMAdRequest.ErrorCode errorCode) {
               public void onFailedToReceiveAd(TWMAd ad, TWMAdRequest.ErrorCode errorCode) {
                   mInterstitialListener.onInterstitialFailed(MoPubErrorCode.NETWORK_NO_FILL);
                   if(mInterstitialListener != null)
                      mInterstitialListener.onInterstitialFailed(MoPubErrorCode.NETWORK_NO_FILL);
               }
               }
    
    
               @Override
               @Override
               public void onPresentScreen(TWMAd ad) {
               public void onPresentScreen(TWMAd ad) {
                   mInterstitialListener.onInterstitialClicked();
                   if(mInterstitialListener != null)
                      mInterstitialListener.onInterstitialShown();
               }
               }
    
    
               @Override
               @Override
               public void onDismissScreen(TWMAd ad) {
               public void onDismissScreen(TWMAd ad) {
                   mInterstitialListener.onInterstitialDismissed();
                   if(mInterstitialListener != null)
                      mInterstitialListener.onInterstitialDismissed();
               }
               }
    
    
               @Override
               @Override
               public void onLeaveApplication(TWMAd ad) {
               public void onLeaveApplication(TWMAd ad) {
                   mInterstitialListener.onLeaveApplication();
                   if(mInterstitialListener != null)
                      mInterstitialListener.onInterstitialClicked();
               }
               }
    
    
行 70: 行 75:
           if (interstitialAd != null) {
           if (interstitialAd != null) {
               interstitialAd.show();
               interstitialAd.show();
              mInterstitialListener.onInterstitialShown();
           }
           }
       }
       }
行 77: 行 81:
       protected void onInvalidate() {
       protected void onInvalidate() {
           // Called when MoPubInterstitial is being invalidated or destroyed.
           // Called when MoPubInterstitial is being invalidated or destroyed.
          if(interstitialAd != null)
              interstitialAd.setAdListener(null);
       }
       }
    
    

於 2017年9月6日 (三) 05:25 的最新修訂

請建立一個Class並繼承Mopub所提供的CustomEventInterstitial

Class實作內容如下:

 package com.taiwanmobile.pt.adp.mediation;
 
 import android.app.Activity;
 import android.content.Context;
 import android.util.Log;
 
 import com.mopub.mobileads.CustomEventInterstitial;
 import com.mopub.mobileads.MoPubErrorCode;
 import com.taiwanmobile.pt.adp.view.TWMAd;
 import com.taiwanmobile.pt.adp.view.TWMAdRequest;
 import com.taiwanmobile.pt.adp.view.TWMAdViewListener;
 import com.taiwanmobile.pt.adp.view.TWMInterstitialAd;
 
 import java.util.Map;
 
 // 需將本class的完整類別名稱 com.taiwanmobile.pt.adp.mediation.TAMediaMopubInterstitial 填入後台的Custom Event Class欄位
 public class TAMediaMopubInterstitial extends CustomEventInterstitial {
     private static final String TAG = "TAMediaInterstitial";
 
     private TWMInterstitialAd interstitialAd  = null;
     private CustomEventInterstitialListener mInterstitialListener;
 
     @Override
     protected void loadInterstitial(final Context context,
                                     final CustomEventInterstitialListener customEventInterstitialListener,
                                     final Map<String, Object> localExtras,
                                     final Map<String, String> serverExtras) {
         Log.d(TAG, "loadInterstitial(" + serverExtras.get("adUnitId") + ") invoked!!");
 
         mInterstitialListener = customEventInterstitialListener;
 
         String adUnitId = serverExtras.get("adUnitId"); //後台設定的adUnitId會透過此Key值取得
         interstitialAd = new TWMInterstitialAd( (Activity)context, adUnitId );
         interstitialAd.setAdListener(new TWMAdViewListener(){
             @Override
             public void onReceiveAd(TWMAd ad) {
                 if(mInterstitialListener != null)
                     mInterstitialListener.onInterstitialLoaded();
             }
 
             @Override
             public void onFailedToReceiveAd(TWMAd ad, TWMAdRequest.ErrorCode errorCode) {
                 if(mInterstitialListener != null)
                     mInterstitialListener.onInterstitialFailed(MoPubErrorCode.NETWORK_NO_FILL);
             }
 
             @Override
             public void onPresentScreen(TWMAd ad) {
                 if(mInterstitialListener != null)
                     mInterstitialListener.onInterstitialShown();
             }
 
             @Override
             public void onDismissScreen(TWMAd ad) {
                 if(mInterstitialListener != null)
                     mInterstitialListener.onInterstitialDismissed();
             }
 
             @Override
             public void onLeaveApplication(TWMAd ad) {
                 if(mInterstitialListener != null)
                     mInterstitialListener.onInterstitialClicked();
             }
 
         });
         interstitialAd.loadAd(new TWMAdRequest());
 
     }
 
     @Override
     protected void showInterstitial() {
         // Called when MoPubInterstitial Object called show()
         if (interstitialAd != null) {
             interstitialAd.show();
         }
     }
 
     @Override
     protected void onInvalidate() {
         // Called when MoPubInterstitial is being invalidated or destroyed.
         if(interstitialAd != null)
             interstitialAd.setAdListener(null);
     }
 
 }



回MoPub教學