Closed lurongshuang closed 3 years ago
我将代码进行如下改动,兼容 原生模板,期待大佬更新 新版本。
public class CustomCsjProvider extends CsjProvider { @Override public void getNativeAdList(@NotNull Activity activity, @NotNull String adProviderType, @NotNull String alias, int maxCount, @NotNull NativeListener listener) { if (Native.INSTANCE.getNativeAdType() == -1) { throw new IllegalArgumentException("|--------------------------------------------------------------------------------------\n" + " | 必须在每次请求穿山甲的原生广告之前设置类型。\n" + " | 设置方式:\n" + " | CsjProvider.Native.nativeAdType = AdSlot.TYPE_XXX(类型和你的广告位ID一致)。\n" + " | CsjProvider.Native.nativeAdType = AdSlot.TYPE_FEED\n" + " | CsjProvider.Native.nativeAdType = AdSlot.TYPE_INTERACTION_AD\n" + " | CsjProvider.Native.nativeAdType = AdSlot.TYPE_BANNER\n" + " | CsjProvider.Native.nativeAdType = AdSlot.TYPE_CACHED_SPLASH\n" + " | CsjProvider.Native.nativeAdType = AdSlot.TYPE_DRAW_FEED\n" + " | CsjProvider.Native.nativeAdType = AdSlot.TYPE_FULL_SCREEN_VIDEO\n" + " | CsjProvider.Native.nativeAdType = AdSlot.TYPE_REWARD_VIDEO\n" + " | CsjProvider.Native.nativeAdType = AdSlot.TYPE_SPLASH\n" + " | 任选其一\n" + " |--------------------------------------------------------------------------------------"); } callbackFlowStartRequest(adProviderType, listener);
//设置广告参数
AdSlot adSlot = new AdSlot.Builder()
.setCodeId(TogetherAdCsj.INSTANCE.getIdMapCsj().get(alias))
.setSupportDeepLink(Native.INSTANCE.getSupportDeepLink())
.setAdCount(maxCount)
.setExpressViewAcceptedSize(Native.INSTANCE.getImageAcceptedSizeWidth$csj_release(), Native.INSTANCE.getImageAcceptedSizeHeight$csj_release())
.setImageAcceptedSize(Native.INSTANCE.getImageAcceptedSizeWidth$csj_release(), Native.INSTANCE.getImageAcceptedSizeHeight$csj_release())
.build();
TTAdSdk.getAdManager().createAdNative(activity).loadNativeExpressAd(adSlot, new TTAdNative.NativeExpressAdListener() {
@Override
public void onError(int code, String message) {
callbackFlowFailed(adProviderType, listener, "错误码: " + code + "}, 错误信息" + message);
}
@Override
public void onNativeExpressAdLoad(List<TTNativeExpressAd> ads) {
if (ads == null || ads.size() == 0) {
callbackFlowFailed(adProviderType, listener, "请求成功,但是返回的list为空");
return;
}
callbackFlowLoaded(adProviderType, listener, ads);
}
});
}
@Override
public boolean nativeAdIsBelongTheProvider(@NotNull Object adObject) {
return true;
}
public class NativeViewCsjSimple6 extends BaseNativeView { @Override public void showNative(@NotNull String s, @NotNull Object o, @NotNull ViewGroup viewGroup, @Nullable NativeViewListener nativeViewListener) { Log.e("", ""); com.bytedance.sdk.openadsdk.core.nativeexpress.k k = (com.bytedance.sdk.openadsdk.core.nativeexpress.k) o; // viewGroup.removeAllViews(); if (k.getExpressAdView().getParent() == null) { viewGroup.addView(k.getExpressAdView()); } } }
public class NativeTemplateSimple5 extends BaseNativeTemplate {
@Nullable
@Override
public BaseNativeView getNativeView(@NotNull String s) {
if (AdProviderType.GDT.getType().equals(s)) {
return new NativeViewGdtSimple5();
} else if (AdProviderType.CSJ.getType().equals(s)) {
return new NativeViewCsjSimple6();
}
// else if(AdProviderType.BAIDU.getType().equals(s)){ // return new NativeViewBaiduSimple5(); // } return null; } }
CustomCsjProvider.Native.INSTANCE.setNativeAdType(AdSlot.TYPE_FEED);
adHelperNativeRv.getList(new NativeListener() {
@Override
public void onAdLoaded(@NotNull String s, @NotNull List<?> list) {
bindAdListener((List
@Override
public void onAdStartRequest(@NotNull String s) {
//每个提供商请求之前都会回调
}
@Override
public void onAdFailedAll() {
//所有的提供商都失败
}
@Override
public void onAdFailed(@NotNull String s, @Nullable String s1) {
//单个提供商请求失败
}
});
private void bindAdListener(final List
adTmp.setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() {
@Override
public void onAdClicked(View view, int type) {
ToastUtils.s(getActivity(), "广告被点击");
}
@Override
public void onAdShow(View view, int type) {
ToastUtils.s(getActivity(), "广告展示");
}
@Override
public void onRenderFail(View view, String msg, int code) {
ToastUtils.s(getActivity(), msg + " code:" + code);
}
@Override
public void onRenderSuccess(View view, float width, float height) {
//返回view的宽高 单位 dp
ToastUtils.s(getActivity(), "渲染成功");
myAdapter.notifyDataSetChanged();
}
});
ad.render();
}
}
RecyclerView中使用信息流: 穿山甲原生模板广告功能 什么时候可以更新一下呢?