Self-Rendering ad integration. Must-read Native Ad Platform Notes.
Self-rendering ads are a relatively advanced usage in native ads. Developers can obtain all creative materials of the ad for custom layout ad rendering. It is generally implemented nested within the product's own layout. As shown in the screenshots below:
| Fixed Position Display | Info Feed List Display |
|---|---|
![]() |
![]() |
Note: The SDK will not hold references to the ad instance (ATNative) and callback instance (ATNativeNetworkListener), so developers need to ensure that the ad instance is not reclaimed before the ad ends to avoid callback loss.
(1) When the app starts, use ATNative.makeAdRequest to execute ad loading. Request ads in advance so that ads can be quickly displayed when needed.
(2) It is recommended to call entryAdScenario(placementId,scenarioId) after entering a displayable ad scenario to count the cache status of the current Ad Placement. For detailed usage of statistics, see Ad Scenarios for distinguishing data across different business scenarios.
(3) Do not execute the ad loading method in the onNativeAdLoadFail callback, otherwise it will cause many unnecessary requests and may cause the app to lag.
(4) Get the ad object via ATNative.getNativeAd at the position where native ads need to be displayed to check whether it is null:
ATNative.makeAdRequest to load ads.NativeAd ad object. At this point, you can directly call ATNative.makeAdRequest again to preload the next ad (as long as you have called ATNative.getNativeAd, you can directly preload the next ad).(5) It is recommended to configure a preset strategy to improve the ad loading efficiency during the first cold start. For specific instructions and integration tutorials, see SDK Preset Strategy Instructions.
ATNative: Native ad loading class.
| API | Description |
|---|---|
| ATNative(Context context, String nativeTakuPlacementID, ATNativeNetworkListener listener) | Native ad initialization method. nativeTakuPlacementID is obtained by creating a Native Ad Placement in the Taku dashboard. |
| onNativeAdLoaded | Ad load success. |
| onNativeAdLoadFail(AdError error) | Ad load failure. You can get the full error info via AdError.getFullErrorInfo(). Please refer to AdError. Note: Do not execute the ad loading method in this callback for retry, otherwise it will cause many unnecessary requests and may cause the app to lag. |
| makeAdRequest | Initiate a Native ad request. |
Notes
Huawei: When displaying Huawei Native ads, a Huawei close button may be included by default. If the developer calls ATNativePrepareInfo#setCloseView() to set a close button, two close buttons may appear during Huawei Native ad display.
Solution: Before loading native ads, pass HuaweiATConst.CUSTOM_DISLIKE as true and ATAdConst.KEY.AD_CHOICES_PLACEMENT as ATAdConst.AD_CHOICES_PLACEMENT_INVISIBLE via setLocalExtra to hide the Huawei close button display.
ATNative atNative;
NativeAd mNativeAd;
int adViewWidth;
int adViewHeight;
public void loadNativeAd() {
if (atNative == null) {
// Initialize the ad loading object
atNative = new ATNative(this, nativeTakuPlacementID, new ATNativeNetworkListener() {
@Override
public void onNativeAdLoaded() {
Log.i(TAG, "onNativeAdLoaded");
}
@Override
public void onNativeAdLoadFail(AdError adError) {
// Note: Do not execute the ad loading method in this callback for retry, otherwise it will cause many unnecessary requests and may cause the app to lag.
// AdError, please refer to https://newdocs.takuad.com/docs/55cxNt
Log.i(TAG, "onNativeAdLoadFail:" + adError.getFullErrorInfo());
}
});
}
// To resolve Huawei Native ads displaying two close buttons simultaneously, add this code before loading to hide the Huawei close button.
// Map localMap = new HashMap<>();
// localMap.put(HuaweiATConst.CUSTOM_DISLIKE, true);
// localMap.put(ATAdConst.KEY.AD_CHOICES_PLACEMENT, ATAdConst.AD_CHOICES_PLACEMENT_INVISIBLE);
// atNative.setLocalExtra(localMap)
// Initiate ad request
atNative.makeAdRequest();
}
NativeAd: The ad object obtained via ATNative.getNativeAd().
Note: It is recommended to understand Native Ad Platform Notes to avoid display and click issues.
| Method | Description |
|---|---|
| isNativeExpress | Whether it is a template rendering type of ad. |
| renderAdContainer(ATNativeAdView view, View selfRenderView) | Used for ad rendering. The view must use our provided ATNativeAdView. Note: When isNativeExpress() returns false (i.e., self-rendering), selfRenderView must pass the developer's custom View. When it returns true (template rendering), null can be passed. |
| prepare(ATNativeAdView view, ATNativePrepareInfo nativePrepareInfo) | Used to configure ad click events, bind close buttons for self-rendering, control the display position and size of the ad identifier, etc. Called after the renderAdContainer method (by default, all views are clickable, and ad identifiers have default display positions and sizes). |
ATNativeAdView mATNativeAdView; // Container that must be created for rendering ads.
View mSelfRenderView; // Developer custom layout container.
public void showNativeAd(ViewGroup adContainer, int adViewWidth) {
/*
To count scenario arrival rate, related info can be found at "https://help.takuad.com/docs/1RWLAv"
Call the “enter ad scenario” method when the ad triggering conditions are met, for example:
** If the ad scenario is to display an ad after a cleanup is finished, call it when the cleanup is finished;
* 1. First call "entryAdScenario"
* 2. Then call "ATNative#checkAdStatus#isReady" to check if it is displayable
* 3. Finally call "getNativeAd" to display
* 4. Passing the scenario ID into scenario will only result in data reaching the dashboard funnel report (optional).
*/
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.
}
ATNative.entryAdScenario("your Native placementID", "your scenarioID");
// v6.5.80 and above
atNative.entryAdScenario("your scenarioID");
NativeAd nativeAd = atNative.getNativeAd();
// After calling getNativeAd, developers can directly use ATNative#makeAdRequest to initiate preloading of the next ad.
// loadNativeAd();
if (nativeAd != null) {
// Destroy the previously displayed ad object.
if (mNativeAd != null) {
mNativeAd.destory();
}
mNativeAd = nativeAd;
mNativeAd.setNativeEventListener(new ATNativeEventListener() {
@Override
public void onAdImpressed(ATNativeAdView view, ATAdInfo atAdInfo) {
// ATAdInfo can distinguish ad platforms and obtain the ad placement ID of the ad platform, etc.
// Please refer to https://newdocs.takuad.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 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 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 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);
}
(1) Developers can call the ATNativePrepareInfo#setCloseView() method to set the close button into ATNativePrepareInfo for close button binding. (Must be called before calling the 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)
// Render the ad
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 close button listener.
mNativeAd.setDislikeCallbackListener(new ATNativeDislikeListener() {
@Override
public void onAdCloseButtonClick(ATNativeAdView view, ATAdInfo entity) {
Log.i(TAG, "native ad onAdCloseButtonClick");
// Here, the developer can implement the removal of the ad View.
}
});
public void destroyAd() {
if (mNativeAd != null) {
mNativeAd.destory();
}
}
ATNative atNative;
NativeAd mNativeAd;
int adViewWidth;
int adViewHeight;
public void loadNativeAd() {
if (atNative == null) {
// Initialize the ad loading object
atNative = new ATNative(this, nativeTakuPlacementID, new ATNativeNetworkListener() {
@Override
public void onNativeAdLoaded() {
Log.i(TAG, "onNativeAdLoaded");
}
@Override
public void onNativeAdLoadFail(AdError adError) {
// Note: Do not execute the ad loading method in this callback for retry, otherwise it will cause many unnecessary requests and may cause the app to lag.
// AdError, please refer to https://docs.takuad.com/#/zh-cn/android/android_doc/android_test?id=aderror
Log.i(TAG, "onNativeAdLoadFail:" + adError.getFullErrorInfo());
}
});
}
// Initiate ad request
atNative.makeAdRequest();
}
For detailed self-rendering ad sample code, please refer to the NativeAdActivity class in Demo, and for bindSelfRenderView, please refer to the SelfRenderViewUtil class.
NativeAd: The ad object obtained via ATNative.getNativeAd().
| Method | Description |
|---|---|
| getAdMaterial | Returns the ad creative object ATNativeMaterial. •ATNativeMaterial: Ad creative object (the creatives below may all be null, because some ad platforms may not necessarily have all creative information.) |
| Method | Description | Ad Platform Native Ad Guidelines |
|---|---|---|
| getIconImageUrl | Get the URL of the ad icon. | When getAdIconView and getIconImageUrl are both returned, prioritize getAdIconView. Only render one of them. |
| getAdIconView | Get the ad IconView. | When getAdIconView and getIconImageUrl are both returned, prioritize getAdIconView. Only render one of them. |
| getAdMediaView | Get the rendering container for the ad's main image (only available on some ad platforms). It may be a static image or video. Parameter description: view: ad parent container, width: MediaView width configuration. | When getAdMediaView and getMainImageUrl are both returned, prioritize getAdMediaView. Only render one of them. |
| getMainImageUrl | Get the main image URL. | When getAdMediaView and getMainImageUrl are both returned, prioritize getAdMediaView. Only render one of them. |
| getTitle | Get the ad title. | Must render when returned. |
| getDescriptionText | Get the ad description. | Must render when returned. |
| getCallToActionText | Get the ad CTA button text. | Must render when returned. |
| getAdFrom | Get the ad source. | The Nend ad platform must render this information. |
| getAdChoiceIconUrl | Get the URL of the ad identifier icon. | Choose one among getAdLogo, getAdLogoView to render. It may not necessarily exist. |
| getAdLogo | Get the Bitmap of the AdLogo. | Choose one among getAdChoiceIconUrl, getAdLogoView to render. It may not necessarily exist. |
| getAdLogoView | Get the View of the AdLogo. | Choose one among getAdChoiceIconUrl, getAdLogo to render. It may not necessarily exist. |
| getImageUrlList | Get the image URL list. | - |
| getStarRating | Get the ad rating. | - |
| getAdType | Get the ad type (video, image): CustomNativeAd.NativeAdConst.VIDEO_TYPE: Video type. CustomNativeAd.NativeAdConst.IMAGE_TYPE: Image type. CustomNativeAd.NativeAdConst.UNKNOWN_TYPE: Unknown ad type (unsupported platforms or unobtainable ones are all unknown ad types). | - |
| getNativeAdInteractionType | Get the ad interaction type: NativeAdInteractionType.APP_DOWNLOAD_TYPE: Download-type ad; NativeAdInteractionType.H5_TYPE: Web page ad; NativeAdInteractionType.DEEPLINK_TYPE: App redirect ad; NativeAdInteractionType.UNKNOW: Unknown ad type. | - |
| getNativeType | Get the ad type. CustomNativeAd.NativeType.FEED: Info Feed Ad (Native Ad). CustomNativeAd.NativeType.PATCH: Patch Ad. | - |
| getVideoDuration | Get the total video duration (double type, unit: seconds). | - |
| getAdAppInfo | Get the downloaded apk info object. For specific supported platforms, refer to the ATAdAppInfo description below. | - |
| getMainImageWidth | Get the main image width. Unsupported platforms return -1 (v5.9.96 and above supports return). | - |
| getMainImageHeight | Get the main image height. Unsupported platforms return -1 (v5.9.96 and above supports return). | - |
| getVideoWidth | Get the video width. Unsupported platforms return -1 (v5.9.96 and above supports return). | - |
| getVideoHeight | Get the video height. Unsupported platforms return -1 (v5.9.96 and above supports return). | - |
| getAdvertiserName | Get the advertiser name. | - |
| getShakeView(int width, int height, ATShakeViewListener listener) | Get the Shake component. Returns null if the ad does not support the Shake capability. width: Component width, not less than 80dp. height: Component height, not less than 80dp. listener: Component callback (v6.1.40 and above supported, currently only Baidu supports it.) | For specific call sample code, refer to Self-Rendering Shake. |
| getSlideView(int width, int height, int repeat, final ATShakeViewListener listener) | Get the Slide component. The slide area is controlled by the container size. Returns null if the ad does not support Slide. width: Width of the slide guide area. height: Height of the slide guide area. repeat: Repeat count of the animation. The component auto-hides after completion. listener: Component callback (v6.2.60 and above supported, currently only Baidu supports it.) | For specific call sample code, refer to the renderSlideView() method in Demo SelfRenderViewUtil class. |
| getDomain | Returns the advertiser's domain. | Only supported by Yandex. |
| getWarning | Returns the warning text. | Only supported by Yandex. |
| getDownloadProgress | Returns the Apk file download progress. | Only supported by GDT and Baidu. |
| getDownloadStatus | Returns the Apk file download status. For specific statuses, refer to ApkDownloadStatus. | Only supported by Adx, GDT, and Baidu. |
ATNativeImageView: Provided by the SDK for displaying network images (optional; developers are recommended to use their own image loading framework.)
| Method | Description |
|---|---|
| setImage(String imageUrl) | Display a network image. imageUrl: Network image URL. |
| setImage(String imageUrl, int width, int height) | Display a network image. imageUrl: Network image URL. width: Image width. height: Image height. |
ATNativePrepareInfo: Binding relationship encapsulation class.
| Method | Description |
|---|---|
| setParentView(View parentView) | Bind parent View. |
| setTitleView(View titleView) | Bind title View. Recommended to bind. |
| setIconView(View iconView) | Bind app icon View. Recommended to bind. |
| setMainImageView(View mainImageView) | Bind main image View. Recommended to bind. |
| setDescView(View descView) | Bind description View. Recommended to bind. |
| setCtaView(View ctaView) | Bind CTA button View. Recommended to bind. |
| setChoiceViewLayoutParams(FrameLayout.LayoutParams choiceViewLayoutParams) | Set the size and position of the ad identifier. |
| setClickViewList(List | Bind the View collection that can trigger clicks. |
| setCloseView(View closeView) | Bind close button. |
| setAdFromView(View adFromView) | Bind ad source View. Recommended to bind. |
| setAdLogoView(View adLogoView) | Bind AdLogo View. |
| setDomainView(View domainView) | Bind domainView. (Yandex must bind.) |
| setWarningView(View warningView) | Bind warningView. (Yandex must bind.) |
ATNativePrepareExInfo: Inherits from ATNativePrepareInfo. Methods are the same as ATNativePrepareInfo. Additional method descriptions are as follows:
| Method | Description |
|---|---|
| setCreativeClickViewList(List <View> creativeClickViewList) | Bind the click View collection for direct download ads. |
| setPermissionClickViewList(List <View> premissionClickViewList) | Bind the click View collection for 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 product info. |
For China-region platform native self-rendering download-type ads, the six elements are returned.
Developers determine whether NativeAd.getAdMaterial().getAdAppInfo() [Six-element info object for download-type ads] is null. If not null, render the six elements onto the layout.
Note: Not all platforms provide complete six elements, so when rendering, you need to check whether each element return is empty; render only when not empty.
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 appInfoClickViewList = new ArrayList<>();
List privacyClickViewList = new ArrayList<>();
List permissionClickViewList = new ArrayList<>();
// Get the app name. Use TitleView to display AppName.
appnameTextView.setText(TextUtils.isEmpty(adAppInfo.getAppName()) ? "" : adAppInfo.getAppName());
// Get the developer company name.
developerTextView.setText(
TextUtils.isEmpty(adAppInfo.getPublisher()) ? "" : adAppInfo.getPublisher());
// Get the app version number.
versionTextView.setText(
TextUtils.isEmpty(adAppInfo.getAppVersion()) ? "" : adAppInfo.getAppVersion());
appInfoClickViewList.add(developerTextView);
appInfoClickViewList.add(versionTextView);
// Get the product feature URL.
appInfoClickViewList.add(functionTextView);
if (!TextUtils.isEmpty(adAppInfo.getFunctionUrl())) {
functionTextView.setVisibility(View.VISIBLE);
setOpenUrlClickListener(functionTextView, adAppInfo.getFunctionUrl());
} else {
functionTextView.setOnClickListener(null);
functionTextView.setVisibility(View.GONE);
}
// Get the privacy agreement URL.
privacyClickViewList.add(privacyTextView);
if (!TextUtils.isEmpty(adAppInfo.getAppPrivacyUrl())) {
privacyTextView.setVisibility(View.VISIBLE);
setOpenUrlClickListener(privacyTextView, adAppInfo.getAppPrivacyUrl());
} else {
privacyTextView.setVisibility(View.GONE);
privacyTextView.setOnClickListener(null);
}
// Get the permission list URL.
permissionClickViewList.add(permissionTextView);
if (!TextUtils.isEmpty(adAppInfo.getAppPermissonUrl())) {
permissionTextView.setVisibility(View.VISIBLE);
setOpenUrlClickListener(permissionTextView, adAppInfo.getAppPermissonUrl());
} else {
permissionTextView.setVisibility(View.GONE);
permissionTextView.setOnClickListener(null);
}
// Bind view permission, privacy, and product feature click View collections.
if (nativePrepareInfo instanceof ATNativePrepareExInfo) {
((ATNativePrepareExInfo) nativePrepareInfo).setAppInfoClickViewList(
appInfoClickViewList);
((ATNativePrepareExInfo) nativePrepareInfo).setPermissionClickViewList(
permissionClickViewList);
((ATNativePrepareExInfo) nativePrepareInfo).setPrivacyClickViewList(
privacyClickViewList);
}
} else {
sixInfoView.setVisibility(View.GONE);
}
| Method | Description | Supported Networks |
|---|---|---|
| getAppName | Get the app name. | GDT, Baidu, Kuaishou, Pangle (China), Mintegral, Mimo, TapTap, Sigmob, VIVO, OPPO, Huawei |
| getPublisher | Get the developer company name. | GDT, Baidu, Kuaishou, Pangle (China), Mintegral, YouKeYing, Mimo, TapTap, Sigmob, VIVO, OPPO, Huawei |
| getAppVersion | Get the app version number. | GDT, Baidu, Kuaishou, Pangle (China), Mintegral, YouKeYing, Mimo, TapTap, Sigmob, VIVO, OPPO, Huawei |
| getAppPrivacyUrl | Get the privacy agreement URL. | GDT, Baidu, Kuaishou, Pangle (China), Mintegral, YouKeYing, Mimo, Sigmob, TapTap, VIVO |
| getAppPermissonUrl | Get the permission list URL. | GDT, Baidu, Kuaishou, Pangle (China), Mimo, Sigmob, TapTap, VIVO |
| getFunctionUrl | Get the product feature URL. // Added in v6.2.37 | GDT, Baidu, Pangle (China), Sigmob, TapTap, VIVO, Kuaishou |
If getAppPrivacyUrl, getAppPermissonUrl, and getFunctionUrl are empty, you can refer to the above sample code for ATNativePrepareExInfo to bind view permission, privacy, and product feature click View collections.