Template feed ads are relatively simple to use in native ads. Developers do not need to define the UI layout of internal ads. The SDK will provide a fully rendered View for developers to display at a designated location. As shown in the screenshot below:
Fixed Location display | Information flow list display |
---|---|
![]() | ![]() |
(1) Start the application through ATNative.makeAdRequestto perform loading ads. 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) after entering the displayable advertising scene to count the current advertising space Cache status, specific statistical description can be viewed in Advertising scenarios Data that distinguishes 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 advertising object is empty at the location where native advertising needs to be displayed: < /p>
(5) It is recommended to configure a preset strategy: to improve the ad loading effect of the first cold start. For specific instructions and access tutorials, see SDK preset strategy usage instructions
For detailed sample code, please view Demo: Taku SDK Demo. For single information flow ad display, please refer to Demo: NativeAdActivity.java. For information flow list integration method, please refer to Demo. :NativeListActivity.java
Note:
ATNative atNative;
NativeAd mNativeAd;
int adViewWidth;
int adViewHeight;
public void loadNativeAd() {
if (atNative == null) {
//Initialize 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: 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());
}
});
}
Map localMap = new HashMap<>();
localMap.put(ATAdConst.KEY.AD_WIDTH, adViewWidth);//Unit: px, expected width of display advertisement
localMap.put(ATAdConst.KEY.AD_HEIGHT, adViewHeight);//Unit: px, expected display advertisement height
//The following adaptive heights can be set for the platform (provided that the width is set)
//Pangle
localMap.put(TTATConst.NATIVE_AD_IMAGE_HEIGHT, 0);
//gdt(Tencent Ads),ADSize.AUTO_HEIGHT值为-2
localMap.put(GDTATConst.AD_HEIGHT, ADSize.AUTO_HEIGHT);
atNative.setLocalExtra(localMap);
//Initiate advertising request
atNative.makeAdRequest();
}
ATNativeAdView mATNativeAdView; //Container that must be created for rendering advertisements
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
}
NativeAd nativeAd = atNative.getNativeAd();
//Developers can directly use ATNative # makeAdRequest to initiate preloading of the next advertisement after calling getNativeAd
//loadNativeAd();
if (nativeAd != null) {
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 = null;
if (!mNativeAd.isNativeExpress()) {
//Self rendering (if you also need to support self rendering advertisements, you can refer to the integration method of self rendering advertisements)
....
} else {
//Template rendering (template rendering requires this step to be implemented)
mNativeAd.renderAdContainer(mATNativeAdView, null);
}
mNativeAd.prepare(mATNativeAdView, nativePrepareInfo);
}
}
1. Before rendering NativeAd, developers can set up the close button monitoring of template ads
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
}
});
public void destroyAd() {
if (mNativeAd != null) {
mNativeAd.destory();
}
}
For detailed template advertising sample code, please refer to: DemoNativeAdActivity class