MediationNativeAdapter

interface MediationNativeAdapter : MediationAdapter


Adapter for third party ad networks that support native ads.

The typical life-cycle for an adapter is to have [requestNativeAd] called once. At this point the adapter should request an ad from the ad network and report to the listener either [MediationNativeListener.onAdLoaded] or [MediationNativeListener.onAdFailedToLoad]. At the end of the life cycle, a best effort is made to call onDestroy(), though this is not guaranteed. Note that [requestNativeAd] is called on the UI thread so all the standard precautions of writing code on that thread apply. In particular, the code should not call any blocking methods.

The adapter is expected to forward events via the [MediationNativeListener] passed in the [requestNativeAd] call. All parameters necessary to make an ad request should be passed in the [serverParameters], [mediationAdRequest], and [mediationExtras] parameters.

Adapters should make an effort to disable automatic ad refreshing on the client side. Ads that are refreshed may be ignored, not displayed, or counted incorrectly.

Summary

Public functions

Unit
requestNativeAd(
    context: Context,
    listener: MediationNativeListener,
    serverParameters: Bundle,
    mediationAdRequest: NativeMediationAdRequest,
    mediationExtras: Bundle?
)

Called by the mediation library to request a native ad from the adapter.

Inherited functions

From com.google.android.gms.ads.mediation.MediationAdapter
Unit

Tears down the adapter control.

Unit

Called when the application calls onPause on the ad view.

Unit

Called when the application calls onResume on the ad view.

Public functions

requestNativeAd

fun requestNativeAd(
    context: Context,
    listener: MediationNativeListener,
    serverParameters: Bundle,
    mediationAdRequest: NativeMediationAdRequest,
    mediationExtras: Bundle?
): Unit

Called by the mediation library to request a native ad from the adapter.

If the request is successful, the MediationNativeListener.onAdLoaded method should be called.

If the request is unsuccessful, the MediationNativeListener.onAdFailedToLoad method should be called on the listener with an appropriate error cause.

This method is called on the UI thread so all the standard precautions of writing code on that thread apply. In particular your code should not call any blocking methods.

Parameters
context: Context

The Context of the AdView which will contain the native View.

listener: MediationNativeListener

Listener for adapter with callbacks for various events.

serverParameters: Bundle

Additional parameters defined by the publisher on the mediation server side.

mediationAdRequest: NativeMediationAdRequest

Generic parameters for this publisher to use when making his ad request.

mediationExtras: Bundle?

Additional parameters set by the publisher on a per-request basis