createNativeAd

fun createNativeAd(adUnitId: String, watermarkString: String? = null, callback: CreateNativeAdCallback)

Creates an ad object using the provided ad unit ID which provides information about the native ad's assets such as title, description, sponsor text, call to action text, rating, icon URI, main image URI, and video view. All these assets can then be used to stitch together a native ad banner. The result of the ad creation process is returned through the provided callback, which will either contain the created ad object or an error describing the failure. NOTE - The API requires Moloco.initialize to have been called.

Parameters

adUnitId

The unique identifier for the ad unit to load the ad from. This must be a valid ad unit ID

callback

A callback function that will be invoked when the ad creation process is complete. It returns either a valid ad object (e.g., Banner, Interstitial, Rewarded, Native) if successful, or a AdCreateError indicating the type of error that occurred.

Samples

import android.content.Context
import android.widget.FrameLayout
import com.moloco.sdk.internal.MolocoLogger
import com.moloco.sdk.publisher.MolocoAdError.AdCreateError
import com.moloco.sdk.publisher.init.MolocoInitParams

fun main() { 
   //sampleStart 
   /**
 * createXXX calls requires [Moloco.initialize] to have been invoked
 */
Moloco.createNativeAd("MOLOCO_ADUNIT_ID") { nativeAd: NativeAd?, molocoAdCreateError: AdCreateError? ->
    if (nativeAd != null) {
        // Load native ad ...
        nativeAd.load("bid_response", listener = null)
    } else {
        // Use the `adCreateError` to determine the error
    }
} 
   //sampleEnd
}