Menu

self-rendering ads

1. Introduction

Self-rendering advertising integration, Please first understand native advertising platform considerations.

Self-rendering ads are a relatively advanced use in native advertising. Developers can obtain all the creative content of the ad to render ads with customized layouts. Generally, developers will implement it nested in the layout of the product itself. As shown in the screenshot below:

Fixed Location displayInformation flow list display
native_one_demo_pic_thumb native_list_demo_pic_thumb

2. Integration suggestions

Note: The SDK does not hold advertising instances (ATNative) and callback instances (ATNativeNetworkListener), so developers need to ensure that the advertising instances will not be recycled before the advertising ends to avoid callback loss.

(1)Start the application to load ads through ATNative.makeAdRequest. Request ads in advance so they can be displayed quickly when ads need to be triggered.

(2)It is recommended to call entryAdScenario(placementId,scenarioId) to count the cache status of the current ad slot after entering the scene where ads can be displayed. For detailed statistical instructions, you can view scenarios Distinguish data from different business scenarios

(3)It is forbidden to execute the ad loading method in the onNativeAdLoadFail callback, otherwise it will cause a lot of useless requests and may cause the application to freeze.

(4)Use ATNative.getNativeAd to obtain whether the ad object is empty where native ads need to be displayed:

Empty: re-execute ATNative.makeAdRequest to load ads

Not empty: Display the NativeAd advertising object. At this time, you can directly execute ATNative.makeAdRequest to preload the next advertisement (as long as you call ATNative.getNativeAd, you can directly preload the next advertisement)

(5)It is recommended to configure a preset strategy: improve the ad loading effect of the first cold start. For detailed instructions and access tutorials, see SDK preset strategy usage instructions

3.API description

ATNative: Native Ad loading class

APIParametersDescription
ATNativeContext context, String nativeTopOnPlacementID, ATNativeNetworkListener listenerNative advertising initialization method, where nativeTopOnPlacementID is created through the TopOn backgroundNative ad slotobtained
onNativeAdLoaded-Ad loaded successfully
(AdError error)Ad loading failed, all error information can be obtained through AdError.getFullErrorInfo(), please refer to AdError Note: It is forbidden to execute the ad loading method in this callback for retry, otherwise it will cause a lot of useless requests and may cause the application to freeze
makeAdRequest-Initiate Native ad request

Notes

Huawei:

Huawei's native ads may come with a Huawei close button. If the developer calls ATNativePrepareInfo#setCloseView() to set the close button, two close buttons may appear when Huawei's native ads are displayed.

Solution: Before loading pass in HuaweiATConst.CUSTOM_DISLIKE as true through setLocalExtra, and ATAdConst.KEY.AD_CHOICES_PLACEMENT as ATAdConst. AD_CHOICES_PLACEMENT_INVISIBLE, block Huawei close button display

ATNative atNative;
NativeAd mNativeAd;

int adViewWidth;
int adViewHeight;

public void loadNativeAd() {
  if (atNative == null) {
     //Initialize ad loading object
     atNative = new ATNative(this, nativeTopOnPlacementID, new ATNativeNetworkListener() {
                @Override
                public void onNativeAdLoaded() {
                    Log.i(TAG, "onNativeAdLoaded");
                }

                @Override
                public void onNativeAdLoadFail(AdError adError) {
                 //Note: It is prohibited to retry the loading method of advertisements in this callback, otherwise it will cause many useless requests and may cause the application to lag

               //AdError, please refer to https://newdocs.toponad.com/docs/55cxNt
                    Log.i(TAG, "onNativeAdLoadFail:" + adError.getFullErrorInfo());
                }
            });
   }

//Addressing the issue of two close buttons appearing simultaneously in Huawei native advertisements, add this code before loading to block the display of the Huawei close button

//Map<String, Object>localMap=new HashMap<>();

//LocalMap. put (Huawei ATConst. CUSTOM DISLIKE, true);

//LocalMap. put (ATAdConst. KEY. AD-CHOICES-PLACEMENT, ATAdConst. AD-CHOICES-PLACEMENT-INVISIBLE);

//AtNative. setLocalExtra (localMap)



//Initiate advertising request
    atNative.makeAdRequest();
}

3.2 Display advertising

NativeAd: The advertising object obtained through ATNative.getNativeAd()

Note:It is recommended to understand native advertising platform precautions to avoid display and click abnormalities

MethodParametersDescription
isNativeExpressWhether it is a template rendering type of advertisement
renderAdContainer(ATNativeAdView view, View selfRenderView)For ad rendering, the view must use the ATNativeAdView we provide Note: When calling isNativeExpress() to return false (i.e. self-rendering), selfRenderView must pass in the developer-defined View. When returning true (template rendering), null can be passed
prepare(ATNativeAdView view, ATNativePrepareInfo nativePrepareInfo)Used to configure ad clicks Events, binding the close button during self-rendering, controlling the placement and size of the advertising logo, etc. are called after the renderAdContainer method (all views are clickable by default, and those with advertising logos will have default placement and size)


ATNativeAdView mATNativeAdView; //Container that must be created for rendering advertisements
View mSelfRenderView; //A container for developers to customize layouts

public void showNativeAd(ViewGroup adContainer, int adViewWidth) {
    /*
     In order to calculate the scene arrival rate, relevant information can be consulted“ https://newdocs.toponad.com/docs/1RWLAv “

Call the "Enter Advertising Scene" method when the advertising triggering conditions are met, for example:

**If an advertisement pops up after the cleaning is completed, it will be called at the end of the cleaning;

*1. First call "entryAdScenario"

*2. Can calling "ATNative # checkAdStatus # isReady" display

*3. Finally, call "getNativeAd" to display

*4. Scenario ID is passed in to the backend funnel report to receive scene data (not mandatory)
     */
    ATNative.entryAdScenario("your Native placementID", "your scenarioID");
    if (atNative == null) {
        return;
    }
    
    if (!atNative.checkAdStatus().isReady()) {
        return;
    }

    if (mATNativeAdView == null) {
        mATNativeAdView = findViewById(R.id.native_ad_view); //Can be defined in XML layout
    }

    if (mSelfRenderView == null) {
        mSelfRenderView = mATNativeAdView.findViewById(R.id.native_selfrender_view); //Can be defined in XML layout
    }

    NativeAd nativeAd = atNative.getNativeAd();
    //Developers can directly use ATNative # makeAdRequest to initiate preloading of the next advertisement after calling getNativeAd

 
    //loadNativeAd();

    if (nativeAd != null) {
        // Destroy the previously displayed advertising object
        if (mNativeAd != null) {
            mNativeAd.destory();
        }

        mNativeAd = nativeAd;
        mNativeAd.setNativeEventListener(new ATNativeEventListener() {
            @Override
            public void onAdImpressed(ATNativeAdView view, ATAdInfo atAdInfo) {
                //ATAdInfo can distinguish between advertising platforms and obtain advertising space IDs for advertising platforms

               //Please refer to https://newdocs.toponad.com/docs/JSLSJN
                Log.i(TAG, "native ad onAdImpressed:\n" + atAdInfo.toString());
            }

            @Override
            public void onAdClicked(ATNativeAdView view, ATAdInfo atAdInfo) {
                Log.i(TAG, "native ad onAdClicked:\n" + atAdInfo.toString());
            }

            @Override
            public void onAdVideoStart(ATNativeAdView view) {
                Log.i(TAG, "native ad onAdVideoStart");
            }

            @Override
            public void onAdVideoEnd(ATNativeAdView view) {
                Log.i(TAG, "native ad onAdVideoEnd");
            }

            @Override
            public void onAdVideoProgress(ATNativeAdView view, int progress) {
                Log.i(TAG, "native ad onAdVideoProgress:" + progress);
            }
        });

        ATNativePrepareInfo nativePrepareInfo;

        if (!mNativeAd.isNativeExpress()) {
            //Self rendering
            nativePrepareInfo = new ATNativePrepareInfo();

            bindSelfRenderView(this, mNativeAd.getAdMaterial(), mSelfRenderView,
                    nativePrepareInfo);

            mNativeAd.renderAdContainer(mATNativeAdView, mSelfRenderView);
        } else {
            //Template rendering
            mNativeAd.renderAdContainer(mATNativeAdView, null);
        }

        mNativeAd.prepare(mATNativeAdView, nativePrepareInfo);
    }
}
public static void bindSelfRenderView(Context context, ATNativeMaterial adMaterial,
                                      View selfRenderView,
                                      ATNativePrepareInfo nativePrepareInfo) {

    int padding = dip2px(context, 5);
    selfRenderView.setPadding(padding, padding, padding, padding);
    TextView titleView = (TextView) selfRenderView.findViewById(R.id.native_ad_title);
    TextView descView = (TextView) selfRenderView.findViewById(R.id.native_ad_desc);
    TextView ctaView = (TextView) selfRenderView.findViewById(R.id.native_ad_install_btn);
    TextView adFromView = (TextView) selfRenderView.findViewById(R.id.native_ad_from);
    FrameLayout iconArea = (FrameLayout) selfRenderView.findViewById(R.id.native_ad_image);
    FrameLayout contentArea = (FrameLayout) selfRenderView.findViewById(R.id.native_ad_content_image_area);
    final ATNativeImageView logoView = (ATNativeImageView) selfRenderView.findViewById(R.id.native_ad_logo);
    View closeView = selfRenderView.findViewById(R.id.native_ad_close);
    FrameLayout shakeViewContainer = (FrameLayout) selfRenderView.findViewById(R.id.native_ad_shake_view_container);
    FrameLayout slideViewContainer = (FrameLayout) selfRenderView.findViewById(R.id.native_ad_slide_view_container);
    FrameLayout adLogoContainer = selfRenderView.findViewById(R.id.native_ad_logo_container);
    // bind view
    if (nativePrepareInfo == null) {
        nativePrepareInfo = new ATNativePrepareInfo();
    }
    //click views
    List<View> clickViewList = new ArrayList<>();
    String title = adMaterial.getTitle();
    // title
    if (!TextUtils.isEmpty(title)) {
        titleView.setText(title);
        nativePrepareInfo.setTitleView(titleView);//bind title
        clickViewList.add(titleView);
        titleView.setVisibility(View.VISIBLE);
    } else {
        titleView.setVisibility(View.GONE);
    }
     // desc
    String descriptionText = adMaterial.getDescriptionText();
    if (!TextUtils.isEmpty(descriptionText)) {
        descView.setText(descriptionText);
        nativePrepareInfo.setDescView(descView);//bind desc
        clickViewList.add(descView);
        descView.setVisibility(View.VISIBLE);
    } else {
        descView.setVisibility(View.GONE);
    }
    // icon
    View adIconView = adMaterial.getAdIconView();
    String iconImageUrl = adMaterial.getIconImageUrl();
    iconArea.removeAllViews();
    final ATNativeImageView iconView = new ATNativeImageView(context);
    if (adIconView != null) {
        iconArea.addView(adIconView);
        nativePrepareInfo.setIconView(adIconView);//bind icon
        clickViewList.add(adIconView);
        iconArea.setVisibility(View.VISIBLE);
    } else if (!TextUtils.isEmpty(iconImageUrl)) {
        iconArea.addView(iconView);
        iconView.setImage(iconImageUrl);
        nativePrepareInfo.setIconView(iconView);//bind icon
        clickViewList.add(iconView);
        iconArea.setVisibility(View.VISIBLE);
    } else {
        iconArea.setVisibility(View.INVISIBLE);
    }
    // cta button
    String callToActionText = adMaterial.getCallToActionText();
    if (!TextUtils.isEmpty(callToActionText)) {
        ctaView.setText(callToActionText);
        nativePrepareInfo.setCtaView(ctaView);//bind cta button
        clickViewList.add(ctaView);
        ctaView.setVisibility(View.VISIBLE);
    } else {
        ctaView.setVisibility(View.GONE);
    }
    // media view
    View mediaView = adMaterial.getAdMediaView(contentArea);
    List<String> imageList = adMaterial.getImageUrlList();
    
    //some network support return main image width、height,if not support return -1
    int mainImageHeight = adMaterial.getMainImageHeight();
    int mainImageWidth = adMaterial.getMainImageWidth();
    int realMainImageWidth = context.getResources().getDisplayMetrics().widthPixels - dip2px(
            context, 10);
    int realMainHeight = 0;
    //media view or mainImage layout params
    FrameLayout.LayoutParams mainImageParam = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT
            , FrameLayout.LayoutParams.WRAP_CONTENT);
    if (mainImageWidth > 0 && mainImageHeight > 0 && mainImageWidth > mainImageHeight) {
        realMainHeight = realMainImageWidth * mainImageHeight / mainImageWidth;
        mainImageParam.width = realMainImageWidth;
        mainImageParam.height = realMainHeight;
    } else {
        mainImageParam.width = FrameLayout.LayoutParams.MATCH_PARENT;
        //contentArea radio
        mainImageParam.height = realMainImageWidth * 600 / 1024;
    }
    contentArea.removeAllViews();
    if (mediaView != null) {
        if (mediaView.getParent() != null) {
            ((ViewGroup) mediaView.getParent()).removeView(mediaView);
        }
        mainImageParam.gravity = Gravity.CENTER;
        mediaView.setLayoutParams(mainImageParam);
        contentArea.addView(mediaView, mainImageParam);
        contentArea.setVisibility(View.VISIBLE);
    } else if (imageList != null && imageList.size() > 1) {
        MutiImageView mutiImageView = new MutiImageView(context);
        mutiImageView.setImageList(imageList, mainImageWidth, mainImageHeight);
        nativePrepareInfo.setMainImageView(mutiImageView);//bind main image
        contentArea.addView(mutiImageView,
                new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT));
        clickViewList.add(mutiImageView);
        contentArea.setVisibility(View.VISIBLE);
    } else if (!TextUtils.isEmpty(adMaterial.getMainImageUrl())) {
        ATNativeImageView imageView = new ATNativeImageView(context);
        imageView.setImage(adMaterial.getMainImageUrl());
        imageView.setLayoutParams(mainImageParam);
        contentArea.addView(imageView, mainImageParam);
        nativePrepareInfo.setMainImageView(imageView);//bind main image
        clickViewList.add(imageView);
        contentArea.setVisibility(View.VISIBLE);
    } else {
        contentArea.removeAllViews();
        contentArea.setVisibility(View.GONE);
    }
    //Ad Logo
    View adLogoView = adMaterial.getAdLogoView();
    if (adLogoView != null) {
        adLogoContainer.setVisibility(View.VISIBLE);
        adLogoContainer.removeAllViews();
        adLogoContainer.addView(adLogoView);
    } else {
        adLogoContainer.setVisibility(View.GONE);
        String adChoiceIconUrl = adMaterial.getAdChoiceIconUrl();
        Bitmap adLogoBitmap = adMaterial.getAdLogo();
        if (!TextUtils.isEmpty(adChoiceIconUrl)) {
            logoView.setImage(adChoiceIconUrl);
            logoView.setVisibility(View.VISIBLE);
            nativePrepareInfo.setAdLogoView(logoView);//bind ad choice
        } else if (adLogoBitmap != null) {
            logoView.setImageBitmap(adLogoBitmap);
            logoView.setVisibility(View.VISIBLE);
            nativePrepareInfo.setAdLogoView(logoView);//bind ad choice
        } else {
            logoView.setImageBitmap(null);
            logoView.setVisibility(View.GONE);
        }
    }
    //bind layout params for ad choice
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(dip2px(context, 40),
            dip2px(context, 10));//ad choice
    layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;
    nativePrepareInfo.setChoiceViewLayoutParams(layoutParams);
    // ad from
    String adFrom = adMaterial.getAdFrom();

    if (!TextUtils.isEmpty(adFrom)) {
        adFromView.setText(adFrom);
        adFromView.setVisibility(View.VISIBLE);
    } else {
        adFromView.setVisibility(View.GONE);
    }
    nativePrepareInfo.setAdFromView(adFromView);//bind ad from
    nativePrepareInfo.setCloseView(closeView);//bind close button
    
  
    TextView domainView = selfRenderView.findViewById(R.id.native_ad_domain);
    TextView warningView = selfRenderView.findViewById(R.id.native_ad_warning);
     //Yandex require render domain
    String domain = adMaterial.getDomain();
    if (!TextUtils.isEmpty(domain)) {
        domainView.setVisibility(View.VISIBLE);
        domainView.setText(domain);
        clickViewList.add(domainView);
        nativePrepareInfo.setDomainView(domainView);
    } else {
        domainView.setVisibility(View.GONE);
    }
    //Yandex require render warning
    String warning = adMaterial.getWarning();
    if (!TextUtils.isEmpty(warning)) {
        warningView.setVisibility(View.VISIBLE);
        warningView.setText(warning);
        clickViewList.add(warningView);
        nativePrepareInfo.setWarningView(warningView);
    } else {
        warningView.setVisibility(View.GONE);
    }
    
    nativePrepareInfo.setClickViewList(clickViewList);//bind click view list
    //set direct download views
    //if (nativePrepareInfo instanceof ATNativePrepareExInfo) {
    //    List<View> creativeClickViewList = new ArrayList<>();//click views
    //    creativeClickViewList.add(ctaView);
    //    ((ATNativePrepareExInfo) nativePrepareInfo).setCreativeClickViewList(creativeClickViewList);//bind custom view list
    //}
}

public static int dip2px(Context context, float dipValue) {
        float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
}

3.3 Close button description (optional )

1. Developers can set the close button to ATNativePrepareInfo by calling the ATNativePrepareInfo#setCloseView() method to close it. Button binding. (Must be called before calling prepare method)

public void showNativeAd() {
    ...
    int height = adViewWidth * 600 / 1024;
    height = height <= 0 ? FrameLayout.LayoutParams.WRAP_CONTENT : height;

    ATNativePrepareInfo nativePrepareInfo = new ATNativePrepareInfo();

    View selfRenderView = LayoutInflater.from(this).inflate(R.layout.native_ad_item, null);
    bindSelfRenderView(this, mNativeAd.getAdMaterial(), selfRenderView, nativePrepareInfo, height)

    //Rendering advertisements
    mNativeAd.renderAdContainer(anyThinkNativeAdView, selfRenderView);
    mNativeAd.prepare(anyThinkNativeAdView, nativePrepareInfo);
}
public void bindSelfRenderView(Context context, ATNativeMaterial adMaterial, View selfRenderView,     ATNativePrepareInfo nativePrepareInfo, int height) {
    ...
    View closeView = selfRenderView.findViewById(R.id.native_ad_close);//Developer's own close button
    ...
    nativePrepareInfo.setCloseView(closeView);//bind close button
}

2. After correctly binding the close button, set the monitoring of the close button< /p>

 mNativeAd.setDislikeCallbackListener(new ATNativeDislikeListener() {
                @Override
                public void onAdCloseButtonClick(ATNativeAdView view, ATAdInfo entity) {
                    Log.i(TAG, "native ad onAdCloseButtonClick");
                      //Here, developers can implement the removal operation of advertising views
                }
});

3.4 Destroy ads

public void destroyAd() {
    if (mNativeAd != null) {
        mNativeAd.destory();
    }
}

4. Sample code

ATNative atNative;
NativeAd mNativeAd;

int adViewWidth;
int adViewHeight;

public void loadNativeAd() {
  if (atNative == null) {
     //Initialize ad loading object
      atNative = new ATNative(this, nativeTopOnPlacementID, new ATNativeNetworkListener() {
                @Override
                public void onNativeAdLoaded() {
                    Log.i(TAG, "onNativeAdLoaded");
                }

                @Override
                public void onNativeAdLoadFail(AdError adError) {
                    //Note: It is prohibited to retry the loading method of advertisements in this callback, otherwise it will cause many useless requests and may cause the application to lag

                   //AdError, please refer to https://docs.toponad.com/#/zh -Cn/android/android_ Doc/android_ Test? Id=aderror
                    Log.i(TAG, "onNativeAdLoadFail:" + adError.getFullErrorInfo());
                }
            });
   }

  //Addressing the issue of two close buttons appearing simultaneously in Huawei native advertisements, add this code before loading to block the display of the Huawei close button

//Map<String, Object>localMap=new HashMap<>();

//LocalMap. put (Huawei ATConst. CUSTOM DISLIKE, true);

//LocalMap. put (ATAdConst. KEY. AD-CHOICES-PLACEMENT, ATAdConst. AD-CHOICES-PLACEMENT-INVISIBLE);

//AtNative. setLocalExtra (localMap)



//Initiate advertising request
    atNative.makeAdRequest();

}
ATNativeAdView mATNativeAdView; //Container that must be created for rendering advertisements
View mSelfRenderView; //A container for developers to customize layouts

public void showNativeAd(ViewGroup adContainer, int adViewWidth) {
/*
 In order to calculate the scene arrival rate, relevant information can be consulted“ https://docs.toponad.com/#/zh -CN/android/NetworkAccess/scenario/scenario“

Call the "Enter Advertising Scene" method when the advertising triggering conditions are met, for example:

**If an advertisement pops up after the cleaning is completed, it will be called at the end of the cleaning;

*1. First call "entryAdScenario"

*2. Can calling "ATNative # checkAdStatus # isReady" display

*3. Finally, call "getNativeAd" to display

*4. Scenario ID is passed in to the backend funnel report to receive scene data (not mandatory)
 */
    ATNative.entryAdScenario("your Native placementID", "your scenarioID");
    if (atNative == null) {
        return;
    }

    if (!atNative.checkAdStatus().isReady()) {
        return;
    }

    if (mATNativeAdView == null) {
        mATNativeAdView = findViewById(R.id.native_ad_view); //Can be defined in XML layout
    }

    if (mSelfRenderView == null) {
        mSelfRenderView = mATNativeAdView.findViewById(R.id.native_selfrender_view); //Can be defined in XML layout
    }

    NativeAd nativeAd = atNative.getNativeAd();
    //Developers can directly use ATNative # makeAdRequest to initiate preloading of the next advertisement after calling getNativeAd
    //loadNativeAd();

    if (nativeAd != null) {
        // Destroy the previously displayed advertising object
        if (mNativeAd != null) {
            mNativeAd.destory();
        }

        mNativeAd = nativeAd;
        mNativeAd.setNativeEventListener(new ATNativeEventListener() {
            @Override
            public void onAdImpressed(ATNativeAdView view, ATAdInfo atAdInfo) {
               //ATAdInfo can distinguish between advertising platforms and obtain advertising space IDs for advertising platforms

              //Please refer to https://docs.toponad.com/#/zh -Cn/android/android_ Doc/android_ SDK_ Callback_ Access? Id=callback_ Info
                Log.i(TAG, "native ad onAdImpressed:\n" + atAdInfo.toString());
            }

            @Override
            public void onAdClicked(ATNativeAdView view, ATAdInfo atAdInfo) {
                Log.i(TAG, "native ad onAdClicked:\n" + atAdInfo.toString());
            }

            @Override
            public void onAdVideoStart(ATNativeAdView view) {
                Log.i(TAG, "native ad onAdVideoStart");
            }

            @Override
            public void onAdVideoEnd(ATNativeAdView view) {
                Log.i(TAG, "native ad onAdVideoEnd");
            }

            @Override
            public void onAdVideoProgress(ATNativeAdView view, int progress) {
                Log.i(TAG, "native ad onAdVideoProgress:" + progress);
            }
        });

        ATNativePrepareInfo nativePrepareInfo;

        if (!mNativeAd.isNativeExpress()) {
            //Self rendering
            nativePrepareInfo = new ATNativePrepareInfo();

            bindSelfRenderView(this, mNativeAd.getAdMaterial(), mSelfRenderView,
                    nativePrepareInfo);

            mNativeAd.renderAdContainer(mATNativeAdView, mSelfRenderView);
        } else {
            //Template rendering
            mNativeAd.renderAdContainer(mATNativeAdView, null);
        }

        mNativeAd.prepare(mATNativeAdView, nativePrepareInfo);
    }
}

For detailed self rendering advertisement example code, please refer to:The NativeAdActivity class of the Demo,BindSelfRenderView, please refer to the SelfRenderViewUtil class

5. Advertising Material Description

NativeAd: Advertising targets obtained through ATNative. getNativeAd()


MethodParametersDescription
getAdMaterial-Return advertising material object ATNativeMaterial



ATNativeMaterial: Advertising material object (the following materials may all be null, as some advertising platforms may not have all material information)


MethodParametersDescriptionAdvertising Platform Native Advertising Specification
getIconImageUrl-Get the URL of the advertising iconWhen both getAdIconView and getIconImageUrl return simultaneously, prioritize selecting getAdIconView and only render one of them
getAdIconView-Get advertising IconViewWhen both getAdIconView and getIconImageUrl return simultaneously, prioritize selecting getAdIconView and only render one of them
getAdMediaView-The rendering container for obtaining large images of advertisements (only available on some advertising platforms) may be static images and videos. Parameter description: view: advertising parent container, width: MediaView width configurationWhen both getAdMediaView and getMainImageUrl return simultaneously, prioritize selecting getAdMediaView and only render one of them
getMainImageUrl-Obtain large image UrlWhen both getAdMediaView and getMainImageUrl return simultaneously, prioritize selecting getAdMediaView and only render one of them
getTitle-Get advertising titlesWhen returning, rendering is required
getDescriptionText-Get advertising descriptionsWhen returning, rendering is required
getCallToActionText-Get advertising CTA button textWhen returning, rendering is required
getAdFrom-Obtain advertising sourcesNend The advertising platform must render this information
getAdChoiceIconUrl-Obtain the icon URL for the advertising logoChoose one of the options for rendering between getAdLogo and getAdLogoView, which may not necessarily exist
getAdLogo-Get the Bitmap of AdLogoChoose one of the options for rendering between getAdChoiceIconUrl and getAdLogoView, and it may not necessarily exist
getAdLogoView-Get the View of AdLogoChoose one of the options for rendering between getAdChoiceIconUrl and getAdLogo, which may not necessarily exist
getImageUrlList-Obtain a list of URLs for images-
getStarRating-Get ad ratings-
getAdType-Obtain advertising types (videos, images): CustomimNativeAd NativeAdConst VIDEO_ TYPE: Video type: CustomimNativeAd NativeAdConst IMAGE_ TYPE: Image type: Custom Native Ad NativeAdConst UNKNOWN_ TYPE: Unknown advertising type (unsupported platforms or those that cannot be obtained are all unknown advertising types)-
getNativeAdInteractionType-Obtain the interaction type of the advertisement: NativeAdInteractionType APP_ DOWNLOAD_ TYPE: Download type advertising; NativeAdInteractionType H5_ TYPE: Native AdInteractionType for web advertising DEEPLINK_ TYPE: Application jump type advertisement NativeAdInteractionType UNKNOW: Unknown advertising type-
getNativeType-Get the advertising type CustomimNativeAd NativeType FEED: Information flow advertising (native advertising) Customized NativeAd NativeType PATCH: Patch advertising-
getVideoDuration-Obtain the total duration of the video (double type, unit: seconds)-
getAdAppInfo-Obtain the downloaded APK information object. For specific support platforms, please refer to the ATAdAppInfo description below-
getMainImageWidth-Obtain the width of the large image, unsupported platforms will return -1 (supported for v5.9.96 and above)-
getMainImageHeight-Obtain the height of the large image, unsupported platforms will return -1 (supported for v5.9.96 and above)-
getVideoWidth-Obtain the width of the video, unsupported platforms will return -1 (supported for v5.9.96 and above)-
getVideoHeight-Obtain the height of the video, unsupported platforms will return -1 (supported for v5.9.96 and above)-
getAdvertiserName-Obtain the advertiser's name-
getShakeView(int width, int height, ATShakeViewListener listener)Obtain the Shake One Shake component. If the advertisement does not support Shake One Shake capability, return null width: component width, not less than 80dp height: component height, not less than 80dp listener: component callback (supported by v6.1.40 and above, currently only supported by Baidu)Specific call example code can be referred to Self rendering shake
getSlideView(int width, int height, int repeat, final ATShakeViewListener listener)Get a sliding component, the sliding area is controlled by the container size. If the advertisement does not support sliding, return null width: width and height of the sliding guide area: high repeat of the sliding guide area: number of repetitions of the animation. After completion, automatically hide the component listener: callback of the component (supported in v6.2.60 and above versions, currently only supported by Baidu)Specific call example code can be referred to The renderSlideView() method of the SelfRenderViewUtil class in Demo
getDomain-Return the domain name of the advertiserOnly supported by Yandex
getWarning-Return warning textOnly supported by Yandex
getDownloadProgress-Return to Apk file download progressOnly supported by Youlianghui and Baidu
getDownloadStatus-The specific status of returning Apk file download status can be referred toApkDownloadStatusThe specific status of returning Apk file download status can refer to ApkDownloadStatus

ATNativeImageView: provided by the SDK for displaying network images (optional, it is recommended that developers use their own image loading framework)


MethodParametersDescription
setImage(String imageUrl)Display network image imageUrl: Network image URL
setImage(String imageUrl, int width, int height)Display network image imageUrl: Network image URL width: Image width height: Image height

6. binding

ATNativePrepareInfo:Binding relationship encapsulation class


MethodParametersDescription
setParentView(View parentView)Bind Parent View
setTitleView(View titleView)Bind the title View, it is recommended to bind it
setIconView(View iconView)Bind the application icon View, it is recommended to bind it
setMainImageView(View mainImageView)Bind the large image view, it is recommended to bind it
setDescView(View descView)Bind Description View, it is recommended to bind
setCtaView(View ctaView)Bind CTA button View, it is recommended to bind
setChoiceViewLayoutParams(FrameLayout.LayoutParams choiceViewLayoutParams)Set the size and position of advertising signs
setClickViewList(ListBind a collection of views that can trigger clicks
setCloseView(View closeView)Bind close button
setAdFromView(View adFromView)Bind the advertising source View, it is recommended to bind it
setAdLogoView(View adLogoView)Bind AdLogo View
setDomainView(View domainView)Bind domainView (Yandex must be bound)
setWarningView(View warningView)Bind warningView (Yandex must be bound)

ATNativePrepareExInfo:Inherited from ATNativePrepareInfo, with the same method as ATNativePrepareInfo. Additional method descriptions are as follows:


MethodParametersDescription
setCreativeClickViewList(List<View> creativeClickViewList)Bind the Click View collection for directly downloading advertisements
setPermissionClickViewList(List<View> permissionClickViewList)Bind the click view collection with viewing permissions
setPrivacyClickViewList(List<View> privacyClickViewList)Bind the Click View collection for viewing privacy agreements
setAppInfoClickViewList(List<View> appInfoClickViewList)Bind the click view collection for viewing products

7. Six Elements of Domestic Download Advertising Download

Six elements of returning native self rendering and downloading advertisements for domestic platforms

7.1 Access suggestions

Developers render the six element information object of a download advertisement to the layout by checking if NativeAd. getAdMaterial(). getAdAppInfo() is empty. If it is not empty, the six element information will be rendered to the layout


Note: Not all platforms provide complete six elements, so when rendering, it is necessary to determine whether the element return is empty, and then proceed with rendering if it is not empty

7.2 sample code


View sixInfoView = selfRenderView.findViewById(R.id.six_info);
ATAdAppInfo adAppInfo = adMaterial.getAdAppInfo();
if (adAppInfo != null) {
    sixInfoView.setVisibility(View.VISIBLE);
    TextView functionTextView = sixInfoView.findViewById(R.id.function_test);
    TextView developerTextView = sixInfoView.findViewById(R.id.developer_test);
    TextView appnameTextView = sixInfoView.findViewById(R.id.appname_test);
    TextView versionTextView = sixInfoView.findViewById(R.id.version_test);
    TextView privacyTextView = sixInfoView.findViewById(R.id.privacy_test);
    TextView permissionTextView = sixInfoView.findViewById(R.id.permission_test);
    List<View> appInfoClickViewList = new ArrayList<>();
    List<View> privacyClickViewList = new ArrayList<>();
    List<View> permissionClickViewList = new ArrayList<>();
    //Get the application name, you can use TitleView to display the AppName
    appnameTextView.setText(TextUtils.isEmpty(adAppInfo.getAppName()) ? "" : adAppInfo.getAppName());
    //Obtain the developer company name
    developerTextView.setText(
            TextUtils.isEmpty(adAppInfo.getPublisher()) ? "" : adAppInfo.getPublisher());
    //Get the application version number
    versionTextView.setText(
            TextUtils.isEmpty(adAppInfo.getAppVersion()) ? "" : adAppInfo.getAppVersion());
    appInfoClickViewList.add(developerTextView);
    appInfoClickViewList.add(versionTextView);
    //Get product feature URL
    if (!TextUtils.isEmpty(adAppInfo.getFunctionUrl())) {
        functionTextView.setVisibility(View.VISIBLE);
        appInfoClickViewList.add(functionTextView);
        setOpenUrlClickListener(functionTextView, adAppInfo.getFunctionUrl());
    } else {
        functionTextView.setOnClickListener(null);
        functionTextView.setVisibility(View.GONE);
    }
    //Obtain Privacy Agreement URL
    if (!TextUtils.isEmpty(adAppInfo.getAppPrivacyUrl())) {
        privacyTextView.setVisibility(View.VISIBLE);
        privacyClickViewList.add(privacyTextView);
        setOpenUrlClickListener(privacyTextView, adAppInfo.getAppPrivacyUrl());
    } else {
        privacyTextView.setVisibility(View.GONE);
        privacyTextView.setOnClickListener(null);
    }
    //Get permission list URL
    if (!TextUtils.isEmpty(adAppInfo.getAppPermissonUrl())) {
        permissionTextView.setVisibility(View.VISIBLE);
        permissionClickViewList.add(permissionTextView);
        setOpenUrlClickListener(permissionTextView, adAppInfo.getAppPermissonUrl());
    } else {
        permissionTextView.setVisibility(View.GONE);
        permissionTextView.setOnClickListener(null);
    }
    //Bind viewing permissions, privacy, and product features by clicking on the View collection
    if (nativePrepareInfo instanceof ATNativePrepareExInfo) {
        ((ATNativePrepareExInfo) nativePrepareInfo).setAppInfoClickViewList(
                appInfoClickViewList);
        ((ATNativePrepareExInfo) nativePrepareInfo).setPermissionClickViewList(
                permissionClickViewList);
        ((ATNativePrepareExInfo) nativePrepareInfo).setPrivacyClickViewList(
                privacyClickViewList);
    }
} else {
    sixInfoView.setVisibility(View.GONE);
}

7.3 API Description of the Six Element Information Object for ATAdAppInfo Download Advertising

MethodParametersSupport Network
getAppNameGet app nameGTD、BaiDu、KuaiShou、CJS、Mintegral、MiMeng、Taptap、Sigmob
getPublisherObtain the developer company nameGTD、BaiDu、KuaiShou、CJS、Mintegral、YouKeYing、MiMeng、Taptap、Sigmob
getAppVersionGet the application version numberGTD、BaiDu、KuaiShou、CJS、Mintegral、YouKeYing、MiMeng、Taptap、Sigmob
getAppPrivacyUrlObtain Privacy Agreement URLGTD、BaiDu、KuaiShou、CJS、Mintegral、YouKeYing、MiMeng、Sigmob、Taptap
getAppPermissonUrlGet permission list URLGTD、BaiDu、KuaiShou、CJS、MiMeng、Sigmob、Taptap
getFunctionUrlObtain product feature URL//v6.2.37 newly addedGTD、BaiDu、CJS、Sigmob、Taptap


Previous
Native
Next
Things to note about native advertising platforms
Last modified: 2025-05-30Powered by