ManagedRenderingNative - Atmosplay/AtmosplayAds-Android Wiki

Integrate Managed Rendering Native Ad

Managed rendering is a rendering mode of native ad. In this mode, ad will be rendered automatically. This approach simplifies the process of accessing native ad, and you can integrate native ad more convient since you do not need to deal with ad rendering related issues.

Initialization and request

// Create NativeExpressAd object
AtmosplayNativeExpressAd mAtmosplayNativeAd = new AtmosplayNativeExpressAd(mContext, mAppId, mAdUnitId);

// Set listener event of loading ads:
// AtmosplayAdLoadListener: you can set NativeAdLoadListener to get request events from the object's callbacks
mAtmosplayNativeAd.setNativeAdLoadListener(NativeAdLoadListener);

// Call the following method to load ad
mAtmosplayNativeAd.loadAd();

NativeAdLoadListener definition

Creat NativeAd Template Layout

Suppose RecyclerView is carrier of information flow, the layout of NativeTemplateViewHolder itemView we creat is as follows:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#eee">
    <com.atmosplayads.nativead.NativeAdExpressView
        android:id="@+id/nativeAdExpressView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" />
</FrameLayout>

Render NativeAd

In RecyclerView Adapter, fire the function onBindViewHolder(ViewHolder holder, int position)

NativeAd nativeAd = mNativeAds.get(position);
if (nativeAd != null) {
    nativeAd.renderAdView(nativeTemplateViewHolder.nativeTemplateView);
}

Listener

NativeAdLoadListener definition

interface NativeAdLoadListener {
    // Success to request ad, put nativeAd into Adapter for future use
    void onNativeAdLoaded(NativeAd nativeAd);
    // Fail to request ad, check "State Code and Description" section of this doc according to errorCode to locate problem quickly
    void onNativeAdFailed(int errorCode, String msg);
}

Add NativeEventListener

If necessery, you can add listener callback of ad's impression/click as follows

// Set listener event of impression/click ads:
// NativeEventListener: you can set NativeEventListener to get impression/click events from the object's callbacks
nativeAd.setNativeEventListener(NativeEventListener);

NativeEventListener definition

interface NativeEventListener {
    // Ad has been impressed
    void onAdImpressed(View view);
    // Ad has been clicked
    void onAdClicked(View view);
}

The NativeExpressAdSample file is the sample code for the native ad(Managed Rendering).