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;

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);
}

Last updated