💡Tips:
- The custom Native Ad Adapter needs to inherit com.anythink.nativead.unitgroup.api.CustomNativeAdapter, override all abstract methods, call the ad network's API in the corresponding methods, and use the member variable
mLoadListenerto callback the load result, and use the member variablemImpressionListenerto callback ad display, click, close, and other event results
💡Tips:
- The custom Native Ad Adapter needs to inherit com.thinkup.nativead.unitgroup.api.CustomNativeAdapter, override all abstract methods, call the ad network's API in the corresponding methods, and use the member variable
mLoadListenerto callback the load result, and use the member variablemImpressionListenerto callback ad display, click, close, and other event results
You only need to inherit CustomNativeAdapter and implement the public abstract methods. After the ad is loaded successfully, you need to wrap the custom ad network's ad information in an object that inherits CustomNativeAd, and callback it through the ATCustomLoadListener.onAdCacheLoaded method. The ad content needs to be provided by overriding CustomNativeAd methods: (The method implementations can be done according to the requirements of the custom ad network; you do not have to implement all of them.)
| Method | Description |
|---|---|
| void loadCustomNetworkAd(Context context, Map serverExtra, Map localExtra) | Implement the ad loading logic of the custom ad network context: Corresponds to the context value passed to ATNative serverExtra: Custom parameters configured on the server. The key-value pairs in the JSON string configured in the TopOn dashboard can all be obtained through the serverExtra parameter localExtra: Custom parameters passed in for this load. The key-value pairs passed in through the ATNative#setLocalExtra() method can be obtained through the localExtra parameter |
| boolean isNativeExpress() | Used to determine whether the Native Ad is a template ad |
| ViewGroup getCustomAdContainer() | Provides the custom ad network's inherent container for loading the Native Ad |
| View getAdMediaView() | Used to provide the large image or video View of the Native Ad (if it is a template ad, the template ad View needs to be provided through this method) |
| String getTitle() | for providing the native ad title |
| String getDescriptionText() | for providing the native ad description |
| String getMainImageUrl() | for providing the URL of the native ad's main image |
| String getIconImageUrl() | for providing the URL of the native ad icon |
| String getCallToActionText() | for providing the CTA button text of the native ad |
| Double getStarRating() | Used to provide the star rating of the Native Ad |
| String getAdChoiceIconUrl() | Used to provide the ad choice icon URL of the Native Ad |
| String getAdFrom() | Used to provide the ad source text of the Native Ad |
| List |
Used to provide the image list of the Native Ad |
| void prepare(View view, ATNativePrepareInfo nativePrepareInfo) | for configuring ad click events, binding self-rendering elements, etc view: The container for displaying the Native Ad nativePrepareInfo: for binding self-rendering elements and click events for self-rendering ads |
| void clear(View view) | Implement the removal of ad click event bindings view: The container for displaying the Native Ad |
| void onResume() | Executed when the native ad is displayed |
| void onPause() | Executed when the native ad is not being displayed |
| void destory() | Executed when the native ad is destroyed |
You only need to inherit CustomNativeAdapter and implement the public abstract methods. After the ad is loaded successfully, you need to wrap the custom ad network's ad information in an object that inherits CustomNativeAd, and callback it through the TUCustomLoadListener.onAdCacheLoaded method. The ad content needs to be provided by overriding CustomNativeAd methods: (The method implementations can be done according to the requirements of the custom ad network; you do not have to implement all of them.)
| Method | Description |
|---|---|
| void loadCustomNetworkAd(Context context, Map serverExtra, Map localExtra) | Implement the ad loading logic of the custom ad network context: Corresponds to the context value passed to TUNative serverExtra: Custom parameters configured on the server. The key-value pairs in the JSON string configured in the TopOn dashboard can all be obtained through the serverExtra parameter localExtra: Custom parameters passed in for this load. The key-value pairs passed in through the TUNative#setLocalExtra() method can be obtained through the localExtra parameter |
| boolean isNativeExpress() | Used to determine whether the Native Ad is a template ad |
| ViewGroup getCustomAdContainer() | Provides the custom ad network's inherent container for loading the Native Ad |
| View getAdMediaView() | Used to provide the large image or video View of the Native Ad (if it is a template ad, the template ad View needs to be provided through this method) |
| String getTitle() | for providing the native ad title |
| String getDescriptionText() | for providing the native ad description |
| String getMainImageUrl() | for providing the URL of the native ad's main image |
| String getIconImageUrl() | for providing the URL of the native ad icon |
| String getCallToActionText() | for providing the CTA button text of the native ad |
| Double getStarRating() | Used to provide the star rating of the Native Ad |
| String getAdChoiceIconUrl() | Used to provide the ad choice icon URL of the Native Ad |
| String getAdFrom() | Used to provide the ad source text of the Native Ad |
| List |
Used to provide the image list of the Native Ad |
| void prepare(View view, TUNativePrepareInfo nativePrepareInfo) | for configuring ad click events, binding self-rendering elements, etc view: The container for displaying the Native Ad nativePrepareInfo: for binding self-rendering elements and click events for self-rendering ads |
| void clear(View view) | Implement the removal of ad click event bindings view: The container for displaying the Native Ad |
| void onResume() | Executed when the native ad is displayed |
| void onPause() | Executed when the native ad is not being displayed |
| void destory() | Executed when the native ad is destroyed |
After the custom ad network's information is wrapped in an object that inherits CustomNativeAd, you can execute ad event callbacks through the methods in CustomNativeAd:
| Method | Description |
|---|---|
| void notifyAdClicked() | Callback executed when the ad is clicked |
| void notifyAdDislikeClick() | Callback executed when the Dislike button of the ad is clicked (optional) |
| void notifyAdVideoStart() | Callback executed when the ad video starts playing (optional) |
| void notifyAdVideoEnd() | Callback executed when the ad video ends (optional) |
For code details, please refer to the sample Adapter in the Demo