Help Center/Details/

Self-rendering Feed Ads

Introduction

Self-rendering information flow: It is an information flow advertisement with a customizable layout. It contains four basic styles: big picture, small picture, group picture and video, phone call, application download, jump to landing page, jump Four types of interaction to the browser. Title and description length is 6-26 characters

Supported ad sizes:

  • Large picture (Picture with aspect ratio: 1.78)
  • Video (Aspect ratio: 1.78 video)
  • Small image (Picture with aspect ratio: 1.52)
  • Group pictures (three pictures with aspect ratio: 1.52)

Permission

**Self-rendering information flow ads: ** Reclaimed and no longer available for creation

Self-rendering information flow request method

Create TTAdNative object

//创建TTAdNative对象,createAdNative(Context context) context需要传入Activity对象
TTAdNative mTTAdNative = TTAdSdk.getAdManager().createAdNative(this);

Create ad request type parameter AdSlot

AdSlot adSlot = new AdSlot.Builder()
         .setCodeId(codeId)
         .setImageAcceptedSize(640, 320) // unit px
         .setAdCount(3) //The number of requested ads is 1 to 3
         .build();

Parameter Description

Parameters Description
setCodeId The code bit ID created by the platform starts with 9 and 9 digits
setAdCount The number of requests is 1-3, it is recommended to set 1
setImageAcceptedSize Set the size of the requested ad Unit: px

Request ads

Call the TTAdNative.loadFeedAd(AdSlot adSlot, FeedAdListener listener) method to load the feed asynchronously

mTTAdNative.loadFeedAd(adSlot, new TTAdNative.FeedAdListener() {
	//请求广告失败
    @Override
    public void onError(int code, String message) {

      }
    //请求广告成功
    @Override
    public void onFeedAdLoad(List<TTFeedAd> ads) {
       
     }
});

FeedAdListener description

Callback Description
onError() Request failed callback
onFeedAdLoad() Request success callback

TTFeedAd interface description

public interface TTFeedAd {

    /**
     * 获取穿山甲logo,图片大小:80*80
     *
     * @return bitmap对象
     */
    Bitmap getAdLogo();

    /**
     * 广告标题
     *
     * @return
     */
    String getTitle();

    /**
     * 广告描述
     *
     * @return
     */
    String getDescription();

    /**
     * 广告来源
     *
     * @return
     */
    String getSource();

    /**
     * 广告图标Image
     *
     * @return
     */
    TTImage getIcon();

    /**
     * 广告图片Image list
     *
     * @return
     */
    List<TTImage> getImageList();

    /**
     * 得到Feed广告交互类型
     *
     * @return 2:在浏览器打开网页,3:在app中打开,4:下载应用,5:拨打电话 其它:未知类型
     */
    int getInteractionType();

    /**
     * 得到Feed广告图片模式
     *
     * @return 3 大图 2小图 4 组图 5 视频 其它:未知类型
     */
    int getImageMode();
 
    /**
     * 获取负反馈选项数据
     *
     * @return
     */
    List<FilterWord> getFilterWords();

    /**
     * 获取“为什么看到此广告”的原因 - //3410版本新增
     */
    PersonalizationPrompt getPersonalizationPrompt();

    /**
     * 得到dislike dialog
     *
     * @param activity 建议传当前activity,否则可能会影响dislike对话框弹出
     * @return
     */
    TTAdDislike getDislikeDialog(Activity activity);

    /**
     * 自定义dislike dialog
     *
     * @param dialog 自定义dialog,需要由外部传入
     * @return
     */
    TTAdDislike getDislikeDialog(TTDislikeDialogAbstract dialog);

    /**
     * 获取下载状态控制器
     */
    DownloadStatusController getDownloadStatusController();

    /**
     * 注册可点击的View,click/show会在内部完成
     *
     * @param container 渲染广告最外层的ViewGroup
     * @param clickView 可点击的View
     */
    void registerViewForInteraction(@NonNull ViewGroup container, @NonNull View clickView, AdInteractionListener listener);

    /**
     * 注册可点击的View,click/show会在内部完成
     *
     * @param container     渲染广告最外层的ViewGroup
     * @param clickViews    可点击的View的列表
     * @param creativeViews 用于下载或者拨打电话的View
     */
    void registerViewForInteraction(@NonNull ViewGroup container, @NonNull List<View> clickViews, @Nullable List<View> creativeViews, AdInteractionListener listener);

    /**
     * 注册可点击的View,click/show会在内部完成,注册dislike按钮
     *
     * @param container     渲染广告最外层的ViewGroup
     * @param clickViews    可点击的View的列表
     * @param creativeViews 用于下载或者拨打电话的View
     * @param dislikeView   dislike按钮
     * @param listener      点击回调
     */
    void registerViewForInteraction(@NonNull ViewGroup container, @NonNull List<View> clickViews, @Nullable List<View> creativeViews, @Nullable View dislikeView, AdInteractionListener listener);

    /**
     * 设置下载监听器
     */
    void setDownloadListener(TTAppDownloadListener downloadListener);

    /**
     * 兼容下载类广告,使用activity申请权限
     */
    void setActivityForDownloadApp(@NonNull Activity activity);

    /**
     * 获取广告的view,如视频广告的view,在广告平台可设置是否自动播放、是否静音等。
     *
     * @return
     */
    View getAdView();

    /**
     * 信息流视频广告回调接口
     */
    interface VideoAdListener {

        /**
         * 视频广告加载成功
         *
         * @param ad
         */
        void onVideoLoad(TTFeedAd ad);

        /**
         * 视频广告加载失败(原生MediaPlayer内部提供的错误类型)
         * @param errorCode 错误类型:
         *                  MEDIA_ERROR_UNKNOWN
         *                  MEDIA_ERROR_SERVER_DIED
         *
         * @param extraCode 额外错误信息
         *                  MEDIA_ERROR_IO
         *                  MEDIA_ERROR_MALFORMED
         *                  MEDIA_ERROR_UNSUPPORTED
         *                  MEDIA_ERROR_TIMED_OUT
         *                  MEDIA_ERROR_SYSTEM
         *
         */
        void onVideoError(int errorCode, int extraCode);

        /**
         * 视频广告播放回调
         *
         * @param ad
         */
        void onVideoAdStartPlay(TTFeedAd ad);

        /**
         * 视频广告暂停回调
         *
         * @param ad
         */
        void onVideoAdPaused(TTFeedAd ad);

        /**
         * 视频广告续播
         *
         * @param ad
         */
        void onVideoAdContinuePlay(TTFeedAd ad);
    }


    void setVideoAdListener(VideoAdListener videoAdListener);

}

Information flow advertising behavior monitoring

Important!!! AdInteractionListener involves advertising billing, convertView must be called correctly and ViewGroup must be used

After loading the information flow advertisement, the access party needs to register the view that can be clicked in the information flow advertisement, that is, the TTFeedAd.registerViewForInteraction() method to realize the functional interaction and calculation of the advertisement.
Contains the registration of the graphic click area and the registration of the additional creative button click area. For landing page ads, the user clicks on the graphic ad area to jump to the corresponding landing page, and clicks on the additional creative area to perform operations such as phone calls and application downloads.

Note: If you need to click on the graphic area to download or make a call, please pass the view of the graphic area to the creativeViewList, the detailed code is as follows

The sample code of the registration click View example is as follows, the sample fragment is called in the BaseAdapter getView() method of Demo

/**
  * 注册可点击的View,click/show会在内部完成
  * @param container     渲染广告最外层的ViewGroup
  * @param clickViews    可点击的View的列表
  * @param creativeViews 用于下载或者拨打电话的View
  */
// 可以被点击的view, 也可以把convertView放进来意味整个item可被点击,点击会跳转到落地页
List<View> clickViewList = new ArrayList<View>();
clickViewList.add(convertView);
// 创意点击区域的view 点击根据不同的创意进行下载或拨打电话动作
//如果需要点击图文区域也能进行下载或者拨打电话动作,请将图文区域的view传入creativeViewList
List<View> creativeViewList = new ArrayList<View>();
creativeViewList.add(adViewHolder.mCreativeButton);
// 注册普通点击区域,创意点击区域。重要! 这个涉及到广告计费及交互,必须正确调用。convertView必须使用ViewGroup。
ad.registerViewForInteraction((ViewGroup) convertView, images, clickViewList, creativeViewList,adViewHolder.mDislike,new TTNativeAd.AdInteractionListener() {

    // 点击普通区域的回调
    @Override
    public void onAdClicked(View view, TTNativeAd ad) {
       
    }
    
    // 点击创意区域的回调
    @Override
    public void onAdCreativeClick(View view, TTNativeAd ad) {
       
    }
    
    // 广告曝光展示的回调
    @Override
    public void onAdShow(TTNativeAd ad) {
       
    }
});

AdInteractionListener description

Callback Description
onAdClicked() Click the common area callback
onAdCreativeClick() Click on creative area callback
onAdShow() Advertising display callback

Information flow video callback interface

ad.setVideoAdListener(new TTFeedAd.VideoAdListener() {

    //视频加载成功
    @Override
    public void onVideoLoad(TTFeedAd ad) {

    }
    
    //视频加载失败
    @Override
    public void onVideoError(int errorCode, int extraCode) {

    }

    //视频开始播放
    @Override
    public void onVideoAdStartPlay(TTFeedAd ad) {

    }

    //视频暂停播放
    @Override
    public void onVideoAdPaused(TTFeedAd ad) {

    }

    //视频继续播放
    @Override
    public void onVideoAdContinuePlay(TTFeedAd ad) {

    }
    
    //视频播放进度
    @Override
    public void onProgressUpdate(long current, long duration) {
      
    }
    
    //视频完成播放
    @Override
    public void onVideoAdComplete(TTFeedAd ad) {
       
    }
});

VideoAdListener description

Callback Description
onVideoLoad() Video loading success callback
onVideoError() Video loading failed callback
onVideoAdStartPlay() Video start playing callback
onVideoAdPaused() Video ad pause callback
onVideoAdContinuePlay() Video ad needs to play callback
onProgressUpdate() Video playback progress callback
onVideoAdComplete() Video playback complete callback

App download status controller

When the returned advertisement is of the application download type, that is, ad.getInteractionType() == TTAdConstant.INTERACTION_TYPE_DOWNLOAD, the access party can call the following sample code to access the Feed ad download controller:

private void bindDownLoadStatusController(AdViewHolder adViewHolder, final TTFeedAd ad) {
    final DownloadStatusController controller = ad.getDownloadStatusController();
    adViewHolder.mStopButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (controller != null) {
                controller.changeDownloadStatus();
                Toast.makeText(mContext, "改变下载状态", Toast.LENGTH_SHORT).show();
                Log.d(TAG, "改变下载状态");
            }
        }
        });
    adViewHolder.mRemoveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (controller != null) {
                controller.cancelDownload();
                Toast.makeText(mContext, "取消下载", Toast.LENGTH_SHORT).show();
                Log.d(TAG, "取消下载");
            }
        }
    });
}
//下载监听设置
TTAppDownloadListener downloadListener = new TTAppDownloadListener() {
    //未开始下载
    @Override
    public void onIdle() {

     }
    /**
     * 下载中回调
     * @param totalBytes 安装包总字节数 -1 :未知
     * @param currBytes 当前已下载的字节数
     * @param fileName 下载文件名称
     * @param appName 当前下载的APP名
     */
    @SuppressLint("SetTextI18n")
    @Override
    public void onDownloadActive(long totalBytes, long currBytes, String fileName, String appName) {
       
    }
    
     /**
     * 下载暂停回调
     * @param totalBytes 安装包总字节数 -1 :未知
     * @param currBytes 当前已下载的字节数
     * @param fileName 下载文件名称
     * @param appName 当前下载的APP名
     */
    @SuppressLint("SetTextI18n")
    @Override
    public void onDownloadPaused(long totalBytes, long currBytes, String fileName, String appName) {
      
    }
    
     /**
     * 下载失败回调
     * @param totalBytes 安装包总字节数 -1 :未知
     * @param currBytes 当前已下载的字节数
     * @param fileName 下载文件名称
     * @param appName 当前下载的APP名
     */
    @Override
    public void onDownloadFailed(long totalBytes, long currBytes, String fileName, String appName) {
       
    }

     /**
     * 安装完成回调
     * @param fileName 下载文件名称
     * @param appName 当前下载的APP名
     */
    @Override
    public void onDownloadFinished(long totalBytes, String fileName, String appName) {

    }
    /**
     * 下载完成回调
     * @param totalBytes 安装包总字节数 -1 :未知
     * @param fileName 下载文件名称
     * @param appName 当前下载的APP名
     */
    @Override
    public void onInstalled(String fileName, String appName) {
       
    }
   
};

TTAppDownloadListener description

Callback Description
onIdle() Binding download listener callback
onDownloadActive() Callback in downloading
onDownloadPaused() Download Paused Callback
onDownloadFailed() Download failed callback
onDownloadFinished() Download complete callback
onInstalled() Installation complete callback

Information flow advertising access Dislike

After obtaining TTFeedAd, call TTFeedAd.getDislikeDialog() to obtain the TTAdDislike object, and then set the user selection result callback for the object.

The following logic is the logic in the CSJ version 3500 SDK. SDK developers below 3500 version can refer to the corresponding demo for integration

private void bindDislikeAction(View dislike, final TTFeedAd ad, boolean isCustomDislike) {
        if (isCustomDislike) {
            // 使用自定义Dislike,用户选择"为什么看到此广告",开发者需要执行startPersonalizePromptActivity逻辑进行跳转
            final DislikeInfo dislikeInfo = ad.getDislikeInfo();
            if (dislikeInfo == null || dislikeInfo.getFilterWords() == null || dislikeInfo.getFilterWords().isEmpty()) {
                return;
            }
            final DislikeDialog dislikeDialog = new DislikeDialog(this, dislikeInfo);
            dislikeDialog.setOnPersonalizationPromptClick(new DislikeDialog.OnPersonalizationPromptClick() {
                @Override
                public void onClick(PersonalizationPrompt personalizationPrompt) {
                    TToast.show(FeedVideoActivity.this, "点击了为什么看到此广告");
                }
            });
            ad.setDislikeDialog(dislikeDialog);
            dislike.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dislikeDialog.show();
                }
            });
        } else {
            // 使用默认Dislike
            final TTAdDislike ttAdDislike = ad.getDislikeDialog(this);
            dislike.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (ttAdDislike != null)
                        ttAdDislike.showDislikeDialog();
                }
            });
        }
    }

DislikeInteractionCallback

Callback Description
onItemClick() Callback when user clicks filterWord in the case of custom style
onClick() User clicked "Why see this ad" in the case of custom styles
onSelected() Default dislike style, click filterWord to call back. Developers can remove ads in this callback
onCancel() The default dislike style, click to cancel the callback
onShow() default dislike style, dislike pop-up window display back
onRefuse() The default dislike style, the user repeatedly clicks the dislike button to call back, version 3600 is abolished

Destroy advertising objects

Destroy the ad view in the onDestroy callback method of Activity

//在Activity的onDestroy方法中清空广告对象
@Override
protected void onDestroy() {
    super.onDestroy();
    if (ad != null) {
        ad = null;
    }
}

Reference Demo

Please refer to the CSJ Demo and the listitem_ad_pic.xml file under /res/layout/.
For detailed code of self-rendering rendering information flow using ListView, please refer to FeedListActivity in Demo
Use RecyclerView to see FeedRecyclerActivity in Demo

Self-rendering information flow note:

  1. AdInteractionListener involves advertising billing, and convertView must be called correctly. **ViewGroup must be used.

  2. TTAdDislike supports self-rendering information flow ads, self-rendering Banner ads

Did the content solve your problem?
Contact us