5

I want to implement the Facebook Audience Network "Native Ads" and display them in a RecyclerView at every Nth position in the list. I already got the regular banners running in the same app and have no problems there. However, the native ads don't load and I just get a blank rectangle with no content.

When I check the logfile I can see that I keep ending up in "onError" of nativeAd.setAdListener(new NativeAdListener())... getting this error message:

The display format in the ad request does not match the display format specified for this placement. Each placement can only be used with a single display format. You can create multiple placements in order to use multiple display formats.

My layout XML looks like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/outer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/blue"
android:orientation="vertical"
android:padding="@dimen/outer_padding_listview_item">

<com.facebook.ads.NativeAdLayout
    android:id="@+id/native_ad_container"
    android:layout_width="250dp"
    android:layout_height="280dp"
    android:layout_gravity="center"
    android:background="@color/white"
    android:orientation="vertical" />

FacebookNativeAdListViewItemHolder.java

public class FacebookNativeAdListViewItemHolder extends RecyclerView.ViewHolder {
private static final String TAG = FacebookNativeAdListViewItemHolder.class.getSimpleName();

private final NativeAd nativeAd;
public View view;
private Context context;

@BindView(R.id.outer_layout)
LinearLayout outerLayout;
@BindView(R.id.native_ad_container)
NativeAdLayout nativeAdContainer;

public FacebookNativeAdListViewItemHolder(View view, Context context) {
    super(view);
    ButterKnife.bind(this, view);

    this.view = view;
    this.context = context;

    nativeAd = new NativeAd(context, Konstanten.FACEBOOK_AUDIENCE_NETWORK_NATIVE_AD_IN_RECYCLER_VIEW);

    nativeAd.setAdListener(new NativeAdListener() {
        @Override
        public void onError(Ad ad, AdError adError) {
            Log.d(TAG, "onError(): " + adError.getErrorMessage());
        }

        @Override
        public void onAdLoaded(Ad ad) {
            Log.d(TAG, "FacebookNativeAdListViewItemHolder onAdLoaded()");

            // Render the Native Ad Template
            View adView = NativeAdView.render(context, nativeAd);
            // Add the Native Ad View to your ad container.
            // The recommended dimensions for the ad container are:
            // Width: 280dp - 500dp
            // Height: 250dp - 500dp
            // The template, however, will adapt to the supplied dimensions.
            nativeAdContainer.addView(adView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 800));
        }

        @Override
        public void onAdClicked(Ad ad) {
            Log.d(TAG, "FacebookNativeAdListViewItemHolder onAdClicked()");
        }

        @Override
        public void onLoggingImpression(Ad ad) {
            Log.d(TAG, "FacebookNativeAdListViewItemHolder onLoggingImpression()");
        }

        @Override
        public void onMediaDownloaded(Ad ad) {
            Log.d(TAG, "FacebookNativeAdListViewItemHolder onMediaDownloaded()");
        }
    });

    // Initiate a request to load an ad.
    nativeAd.loadAd();
}

}

It all builds fine and I can see the rectangle in the recyclerview where the native ad should be displayed. But the problem is that it just remains white and there's no content displayed (see screenshot).

enter image description here

Dominik
  • 1,703
  • 6
  • 26
  • 46

2 Answers2

0

You need to add a testing device to show ads

  1. Go to your Monetization Manager from navigation menu select Integration --> Testing
  2. Enable Testing and check on 'Use real advertiser content'
  3. Now add your testing device by adding 'Google Advertiser Id' from your 'Settings->Google Account->Ads'

Click here for more information

Izhan Ali
  • 567
  • 7
  • 17
  • Have tried the testing option already and unfortunately it didn't change anything about the problem. – Dominik Sep 10 '19 at 07:23
0

Eventually I was able to find the problem. The problem was the wrong ad format (rectangle instead of natvie-ad) and therefore wasn't able to display an ad in a native ad container.

Dominik
  • 1,703
  • 6
  • 26
  • 46