Native Ads: FacebookAudienceNetwork
Integrate native ads (Facebook Audience Network)
To use Facebook Audience Networks native ads you need to do the following:
The views used for main image and icon need to be an instances of com.facebook.ads.MediaView
.
private ViewGroup containerView;
private TextView titleView;
private TextView descriptionView;
private com.facebook.ads.MediaView mainImageView;
private com.facebook.ads.MediaView iconView;
private TextView advertiserView;
private TextView ctaView;
private void setupFacebookNativeAd(NativeAdData nativeAd) {
// TODO: create the container view and subviews from layout file
// Title
titleView.setText(nativeAd.getTitle());
// Body
descriptionView.setText(nativeAd.getDescription());
// Advertiser
advertiserView.setText(nativeAd.getAdvertiser());
// CallToAction
ctaView.setText(nativeAd.getCallToAction());
nativeAd.attachToLayout(containerView, mainImageView, iconView, ctaView);
}
private val containerView: ViewGroup? = null
private val titleView: TextView? = null
private val descriptionView: TextView? = null
private val mainImageView: com.facebook.ads.MediaView? = null
private val iconView: com.facebook.ads.MediaView? = null
private val advertiserView: TextView? = null
private val ctaView: TextView? = null
private fun setupFacebookNativeAd(nativeAd: NativeAdData) {
// TODO: create the container view and subviews from layout file
// Title
titleView.text = nativeAd.title
// Body
descriptionView.text = nativeAd.description
// Advertiser
advertiserView.text = nativeAd.advertiser
// CallToAction
ctaView.text = nativeAd.callToAction
nativeAd.attachToLayout(containerView!!, mainImageView, iconView, ctaView)
}
You do not have to fill the main image and icon views, that will be done by Facebook SDK.