檢視 Android Mopub Native 的原始碼
←
Android Mopub Native
跳至導覽
跳至搜尋
由於下列原因,您沒有權限進行編輯此頁面的動作:
您請求的操作只有這個群組的使用者能使用:
使用者
您可以檢視並複製此頁面的原始碼。
請建立一個Class並繼承Mopub所提供的CustomEventNative<br><br> Class實作內容如下:<br> package com.taiwanmobile.pt.adp.mediation; import android.app.Activity; import android.content.Context; import android.util.Log; import android.view.View; import com.mopub.nativeads.CustomEventNative; import com.mopub.nativeads.NativeErrorCode; 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.TWMNativeAd; import org.json.JSONException; import org.json.JSONObject; import java.util.Map; // 需將本class的完整類別名稱 com.taiwanmobile.pt.adp.mediation.TAMediaMopubNative 填入後台的Custom Event Class欄位 public class TAMediaMopubNative extends CustomEventNative { private static final String TAG = "TAMediaMopubNative"; private TWMNativeAd nativeAd; @Override protected void loadNativeAd(final Context context, final CustomEventNativeListener customEventNativeListener, final Map<String, Object> localExtras, final Map<String, String> serverExtras) { Log.d(TAG, "loadNativeAd(" + serverExtras.get("adUnitId") + ") invoked!!"); String adUnitId = serverExtras.get("adUnitId"); '''// 後台設定的adUnitId會透過此Key值取得''' nativeAd = new TWMNativeAd((Activity) context, adUnitId); final TWMediaStaticNativeAd staticNativeAd = new TWMediaStaticNativeAd(nativeAd, customEventNativeListener); nativeAd.setAdListener(staticNativeAd); nativeAd.loadAd(new TWMAdRequest()); } static class TWMediaStaticNativeAd extends com.mopub.nativeads.StaticNativeAd implements TWMAdViewListener { private final CustomEventNativeListener mCustomEventNativeListener; private final TWMNativeAd nativeAd; // Native ad assets. private String longSubject; private String body; private String iconUrl; private String imageUrl; private String targetUrl; public TWMediaStaticNativeAd(final TWMNativeAd nativeAD, final CustomEventNativeListener customEventNativeListener) { mCustomEventNativeListener = customEventNativeListener; nativeAd = nativeAD; } @Override public void destroy() { nativeAd.destroy(); super.destroy(); } @Override public void prepare(View view) { super.prepare(view); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { notifyAdClicked(); nativeAd.handleClick(); } }); notifyAdImpressed(); } // TWMAdViewListener @Override public void onReceiveAd(TWMAd twmAd) { if (nativeAd.isReady()) { JSONObject content = nativeAd.getNativeAdContent(); try { longSubject = (content.has("LONGSUBJECT")) ? content.getString("LONGSUBJECT") : null; body = (content.has("BODY")) ? content.getString("BODY") : null; iconUrl = (content.has("ICONSQUARE")) ? content.getString("ICONSQUARE") : null; imageUrl = (content.has("IMAGE1200X627")) ? content.getString("IMAGE1200X627") : null; targetUrl = (content.has("nurl")) ? content.getString("nurl") : null; if(longSubject != null) setTitle(longSubject); if(body != null) setText(body); if(imageUrl != null) setMainImageUrl(imageUrl); if(iconUrl != null) setIconImageUrl(iconUrl); if(targetUrl != null) setClickDestinationUrl(targetUrl); mCustomEventNativeListener.onNativeAdLoaded(this); } catch (JSONException e) { Log.e(TAG, "Native Content Parse Error: " + e.getMessage()); mCustomEventNativeListener.onNativeAdFailed(NativeErrorCode.INVALID_RESPONSE); } } } @Override public void onFailedToReceiveAd(TWMAd twmAd, TWMAdRequest.ErrorCode errorCode) { mCustomEventNativeListener.onNativeAdFailed(NativeErrorCode.NETWORK_NO_FILL); } @Override public void onPresentScreen(TWMAd twmAd) {} @Override public void onDismissScreen(TWMAd twmAd) {} @Override public void onLeaveApplication(TWMAd twmAd) {} } } <br><br> [[Android Integeration with Mopub Mediation|回MoPub教學]]<br>
返回到「
Android Mopub Native
」。
導覽選單
個人工具
登入
命名空間
頁面
討論
變體
已展開
已摺疊
視圖
閱讀
檢視原始碼
檢視歷史
更多
已展開
已摺疊
搜尋
導覽
首頁
近期變更
隨機頁面
有關 MediaWiki 的說明
工具
連結至此的頁面
相關變更
特殊頁面
頁面資訊