💡Tips
- To implement a custom Native Ad Adapter, you need to extend
com.anythink.nativead.unitgroup.api.CustomNativeAdapter
and override all abstract methods. In the respective methods, you should call the ad platform's API and use the class member variablemLoadListener
to callback the result of the ad loading, and usemImpressionListener
to callback the results of ad display, clicks, and closings.
1. Additional Abstract Methods for Native Ads Implementation
To use this custom native ad integration, you only need to extend CustomNativeAdapter and implement the required abstract methods. After successfully loading the ad, you should wrap the custom ad platform's ad information in an object that inherits from CustomNativeAd, and use the ATCustomLoadListener.onAdCacheLoaded
method to provide the callback. The content of the ad needs to override methods in CustomNativeAd to provide the following. ( Note: The implementation of the methods inside customNativeAd can be tailored according to the requirements of the custom ad platform and not all methods need to be implemented):
Method | Description |
void loadCustomNetworkAd(Context context, Map serverExtra, Map localExtra) | Implement the ad loading logic for the custom network context: The context passed to ATReward, VideoAd, ATInterstitial, ATNative, ATBannerView, ATSplashAd (Note: For splash ads, the context type is Activity). serverExtra: Custom parameters configured on the server. Key-value pairs from the JSON string configured in the TopOn backend can be retrieved through the serverExtra parameter. localExtra: Custom parameters passed during this load, available through the localExtra parameter which includes key-value pairs passed via ATNative#setLocalExtra() . |
boolean isNativeExpress() | Determine if the current native ad is a template ad |
ViewGroup getCustomAdContainer() | Provide a container for loading native ads specific to the custom ad platform |
View getAdMediaView() | Provide a view for the large image or video of the native ad (for template ads, this method should supply the view of the template ad) |
String getTitle() | Provide the title of the native ad |
String getDescriptionText() | Provide the description of the native ad |
String getMainImageUrl() | Provide the URL of the large image of the native ad |
String getIconImageUrl() | Provide the URL of the icon of the native ad |
String getCallToActionText() | Provide the text for the CTA button of the native ad |
Double getStarRating() | Provide the star rating of the native ad |
String getAdChoiceIconUrl() | Provide the URL of the ad's promotional tag |
String getAdFrom() | Provide the ad source text of the native ad |
List<String> getImageUrlList() | Provide the list of images for the native ad |
void prepare(View view, ATNativePrepareInfo nativePrepareInfo) | Configure ad click events, bind custom rendering elements, etc. view: The container displaying the native ad. nativePrepareInfo: Used to bind custom rendering elements and click events for self-rendering ads. |
void clear(View view) | Implement the removal of ad click event bindings view: The container displaying the native ad |
void onResume() | Called when the native ad is displayed |
void onPause() | Called when the native ad is not displayed |
void destory() | Called when the native ad is destroyed |
2. Native Ads Event Callbacks
After wrapping the custom ad platform information in an object inheriting from CustomNativeAd, you can use the methods within CustomNativeAd to execute ad event callbacks:
Method | Description |
void notifyAdClicked() | Called when the ad is clicked |
void notifyAdDislikeClick() | Called when the ad's Dislike button is clicked (optional) |
void notifyAdVideoStart() | Called during video playback of the ad (optional) |
void notifyAdVideoEnd() | Called when the video ends (optional) |
3. Sample code
For detailed code, please refer to FacebookNativeAdapter.java in the Demo.