Help Center/Details/

Self-rendering banner

Introduction

Self-rendering Banner:: Developers can get the material information of the advertisement for stitching

Supported ad sizes:

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

Permission

Self-rendering Banner: Reclaimed and no longer available for creation

Self-rendering Banner request method

Create TTAdNative object

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

Create ad request type parameter AdSlot

Note:
1.setImageAcceptedSize aspect ratio is set according to the ratio checked when creating the code bit ID unit px
2. When setNativeAdType requests native ads, please call this method and set the parameter to TYPE_BANNER

AdSlot adSlot = new AdSlot.Builder()
        .setCodeId(codeId)
        .setSupportDeepLink(true)
        .setImageAcceptedSize(600, 257)
        .setNativeAdType(AdSlot.TYPE_BANNER) //请求原生广告时候,请务必调用该方法,设置参数为TYPE_BANNER
        .setAdCount(1)
        .build();

Parameter Description

Method Description
setCodeId() The code bit ID created by the platform starts with 9 and 9 digits
setImageAcceptedSize() Set the size of the requested template creative unit: px
setNativeAdType() Request ad type
setAdCount() The number of requested ads is 1-3

Request ads

The access party can call loadNativeAd(AdSlot adSlot, @NonNull NativeAdListener listener) to load ads asynchronously

//请求广告
mTTAdNative.loadNativeAd(adSlot, new TTAdNative.NativeAdListener() {
	//请求失败回调
    @Override
    public void onError(int code, String message) {
       
    }
	
	//请求成功回调
    @Override
    public void onNativeAdLoad(List<TTNativeAd> ads) {
        if (ads.get(0) == null) {
              return;
        }
        //bannerView接入方自行创建
        //mBannerContainer是给bannerView留的布局控件
        View bannerView = LayoutInflater.from(mContext).inflate(R.layout.native_ad, mBannerContainer, false);
        if (bannerView == null) {
              return;
        }
         mBannerContainer.removeAllViews();
         mBannerContainer.addView(bannerView);
         //绑定原生广告的数据 根据不同的广告类型类型 在adapter中接入方把获取到广告的元素添加到对应banner的控件上即可
         setAdData(bannerView, ads.get(0));       
    }
});

NativeAdListener

Callback Description
onError() The error code returned by the ad request failed callback indicates the reason for the ad request failure. For details, please see [link](https://www.pangle.cn/help/doc/5de4cc6d78c8690012a90aa5?from=ad. oceanengine.com&id=5de4cc6d78c8690012a90aa5)
onNativeAdLoad() Callback for successful ad request

Notice:

  • Before addView, you need to call the removeAllViews method to remove all the views on the control
    -setNativeAdType(AdSlot.TYPE_INTERACTION_AD)//When requesting native ads, be sure to call this method and set the parameter to TYPE_BANNER
    -Self-rendering banner is to create a view on the FrameLayout control, add advertising elements to the view, and bind the view to the corresponding control

TTFeedAd interface description

Get advertising information, such as title, buttonText, etc., through getAdView(), and customize the entire advertising area to draw as close as possible to the style of your own application

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);

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

/**
  * 注册可点击的View,click/show会在内部完成
  * @param container     渲染广告最外层的ViewGroup
  * @param clickViews    可点击的View的列表
  * @param creativeViews 用于下载或者拨打电话的View
  */
//可以被点击的view, 也可以把nativeView放进来意味整个广告区域可被点击
List<View> clickViewList = new ArrayList<>();
clickViewList.add(nativeView);

//触发创意广告的view(点击下载或拨打电话)
List<View> creativeViewList = new ArrayList<>();

//穿山甲logo
ImageView ad_logo = nativeView.findViewById(R.id.iv_native_ad_logo);
ad_logo.setImageBitmap(nativeAd.getAdLogo());
//如果需要点击图文区域也能进行下载或者拨打电话动作,请将图文区域的view传入
//creativeViewList.add(nativeView);
creativeViewList.add(mCreativeButton);

//重要! 这个涉及到广告计费,必须正确调用。convertView必须使用ViewGroup。
ad.registerViewForInteraction((ViewGroup) nativeView, imageViewList,clickViewList, creativeViewList, imgDislike, 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

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

TTAdDislike

The SDK provides information flow advertisements for the access party. When the user chooses to close the advertisement, the user will be asked in the form of a pop-up window, including the options of "Not interested" and "Have seen" for the user to choose. This feedback is mainly used for the advertising strategy of Toutiao ads on the client side, to optimize and increase the click-through rate of the ads, improve the advertising effect and the revenue of the partners

Note:
If using Dislike logic, initialize TTAdNative mTTAdNative =
When ttAdManager.createAdNative(activity), parameters must be passed into activity

After obtaining TTNativeAd, call TTNativeAd.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 3500 SDK. Developers of the SDK below 3500 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();
                }
            });
        }
    }
Turn off ad monitoring
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

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

Reference Demo

For self-rendered banner ads, please refer to the NativeBannerActivity example in Demo

Self-rendering Banner Note:

  1. The aspect ratio of setImageAcceptedSize is set according to the ratio checked when creating the code bit ID. Unit px
  2. When setNativeAdType requests native ads, be sure to call this method and set the parameter to TYPE_BANNER
Did the content solve your problem?
Contact us