Native Ads: Huawei
Integrate native ads (Huawei)
NativeView
Native ad assets of Huawei SDK are required to be encapsulated within a parent view of a specific type com.huawei.hms.ads.nativead.NativeView
.
The same view must be passed to AATKit via the NativeAdData
method: attachToLayout
.
Also, Huawei displays the native ad main image using an instance of com.huawei.hms.ads.nativead.MediaView
.
private com.huawei.hms.ads.nativead.NativeView containerView;
private TextView titleView;
private TextView descriptionView;
private com.huawei.hms.ads.nativead.MediaView mediaView;
private ImageView iconView;
private TextView ctaView;
private var containerView: com.huawei.hms.ads.nativead.NativeView? = null
private var titleView: TextView? = null
private var descriptionView: TextView? = null
private var mediaView: com.huawei.hms.ads.nativead.MediaView? = null
private var iconView: ImageView? = null
private var ctaView: TextView? = null
Bind Huawei Native Ad Assets
After getting a native ad from the NativeAdPlacement
, you can follow this code example to bind the native ad assets:
private void setupHuaweiAd(NativeAdData nativeAd) {
// TODO: create the container view and subviews from layout file
// Title
containerView.setTitleView(titleView);
titleView.setText(nativeAd.getTitle());
// Ad Icon
containerView.setIconView(iconView);
loadImage(iconView, nativeAd.getIconUrl());
// Body
containerView.setAdSourceView(descriptionView);
descriptionView.setText(nativeAd.getDescription());
// MediaView
containerView.setMediaView(mediaView); //Huawei SDK will fill the passed MediaView automatically
// CallToAction
containerView.setCallToActionView(ctaView);
ctaView.setText(nativeAd.getCallToAction());
nativeAd.attachToLayout(containerView, mediaView, iconView, ctaView);
}
private fun setupHuaweiAd(nativeAd: NativeAdData) {
// TODO: create the container view and subviews from layout file
// Title
containerView.setTitleView(titleView)
titleView.text = nativeAd.title
// Ad Icon
containerView.setIconView(iconView)
loadImage(iconView, nativeAd.iconUrl)
// Body
containerView.setAdSourceView(descriptionView)
descriptionView.text = nativeAd.description
// MediaView
containerView.setMediaView(mediaView) //Huawei SDK will fill the passed MediaView automatically
// CallToAction
containerView.setCallToActionView(ctaView)
ctaView.text = nativeAd.callToAction
nativeAd.attachToLayout(containerView, mediaView, iconView, ctaView)
}