「Android Mopub Interstitial SDK8」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
(新頁面: 請建立一個Class並繼承Mopub所提供的BaseAd<br><br> Class實作內容如下:<br> <source> package com.taiwanmobile.pt.adp.mediation import android.app.Activity import andr...)
 
imported>Wikiuser
 
(未顯示同一使用者於中間所作的 1 次修訂)
行 84: 行 84:


<br><br>
<br><br>
== MoPub後台設定 ==
<br>
: 將上述class完整package設定置MoPub Custom event class
: 將TAmedia所提供的adUnitId設定於MoPub Custom event data(必要)
[[檔案:Mopub interstitial mediation 1.png |600px]]
<br>
[[Android Integeration with Mopub Mediation|回MoPub教學]]<br>
[[Android Integeration with Mopub Mediation|回MoPub教學]]<br>

於 2021年8月31日 (二) 07:58 的最新修訂

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

Class實作內容如下:

package com.taiwanmobile.pt.adp.mediation

import android.app.Activity
import android.content.Context
import com.mopub.common.LifecycleListener
import com.mopub.common.logging.MoPubLog
import com.mopub.mobileads.AdData
import com.mopub.mobileads.BaseAd
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

// 需將本class的完整類別名稱 com.taiwanmobile.pt.adp.mediation.TAMediaMopubInterstitial 填入後台的Custom Event Class欄位
class TAMediaMopubInterstitial : BaseAd() {

    private var adUnitId = ""
    private var interstitialAd: TWMInterstitialAd? = null

    override fun onInvalidate() {
        // Called when MoPubInterstitial is being invalidated or destroyed.
        interstitialAd?.setAdListener(null)
    }

    override fun getLifecycleListener(): LifecycleListener? {
        return null
    }

    override fun getAdNetworkId(): String {
        return adUnitId
    }

    override fun checkAndInitializeSdk(launcherActivity: Activity, adData: AdData): Boolean {
        return false
    }

    override fun load(context: Context, adData: AdData) {
        try {
            setAutomaticImpressionAndClickTracking(false)
            adUnitId = adData.extras.getValue(KEY_AD_UNIT_ID)
            interstitialAd = TWMInterstitialAd(context as Activity, adUnitId)
            interstitialAd?.setAdListener(object : TWMAdViewListener {
                override fun onReceiveAd(ad: TWMAd) {
                    mLoadListener?.onAdLoaded()
                    interstitialAd?.show()
                }

                override fun onFailedToReceiveAd(ad: TWMAd, errorCode: TWMAdRequest.ErrorCode) {
                    mLoadListener?.onAdLoadFailed(MoPubErrorCode.NO_FILL)
                }

                override fun onPresentScreen(ad: TWMAd) {
                    mInteractionListener?.onAdImpression()
                }

                override fun onDismissScreen(ad: TWMAd) {
                    mInteractionListener?.onAdDismissed()
                }

                override fun onLeaveApplication(ad: TWMAd) {
                    mInteractionListener?.onAdClicked()
                }
            })
            interstitialAd?.loadAd(TWMAdRequest())
        } catch (e: Exception) {
            MoPubLog.log(
                    adNetworkId, MoPubLog.AdapterLogEvent.LOAD_FAILED, javaClass.name,
                    MoPubErrorCode.NETWORK_NO_FILL.intCode, MoPubErrorCode.NETWORK_NO_FILL)
            mLoadListener?.onAdLoadFailed(MoPubErrorCode.NETWORK_NO_FILL)
            e.printStackTrace()
        }
    }

    companion object {
        private const val KEY_AD_UNIT_ID = "adUnitId"
    }
}



MoPub後台設定


將上述class完整package設定置MoPub Custom event class
將TAmedia所提供的adUnitId設定於MoPub Custom event data(必要)

Mopub interstitial mediation 1.png


回MoPub教學