插屏广告
简介
该广告类型支持插屏广告、全屏广告混出。
注意事项
①聚合SDK是通过广告位ID发起广告请求的,切记不要使用混淆。
②在广告接入前需要明确各ADN对应聚合SDK广告样式情况,以确保正确完成广告接入,避免由于广告类型不匹配导致接入报错等情况的发生。
③由于各广告平台对于包名校验规则不同,需确保在平台填写的包名符合各ADN平台规范,避免由于包名校验不匹配导致的无广告返回情况的产生。
④广告请求时机,建议在收到SDK初始化成功回调后发起广告请求,当SDK初始化回调一直失败时,建议首先明确appid及广告位ID是否赋值正确、是否有多余空格、是否是网络不稳定导致的超时等,当排查后无法定位问题时,建议通过抓包将config字段下的加密内容提供过来,我方协助定位问题。
⑤如若针对展示失败有重试机制,建议只重试一次即可,避免无限重试引发死循环场景。
接入插全屏广告
一、创建AdView对象
AdView interstialView = AdView(this, requestConfig);
一、创建广告请求AdRequestConfig
val requestConfig: AdRequestConfig = AdRequestConfig.Builder()
.AdType(AdConfig.AD_TYPE_INTERSTITIAL) //广告样式
.slotId("2323534") //广告场景id
.widthDp(300)
.heightDp(300)
.showDownloadConfirmDialog(true)
.build()
三、请求广告
interstialView!!.setListener(object : AdViewListener {
override fun onAdClick() {
}
override fun onAdFailed(arg0: String) {
showInterstialAd?.text = "插屏广告"
showInterstialAd?.isEnabled = true
interstialView?.onDestroyAd()
interstialView = null
Toast.makeText(this@InterstialActivity, arg0, Toast.LENGTH_SHORT).show()
}
override fun onAdReady() {
showInterstialAd?.text = "点击展示插屏广告"
showInterstialAd?.isEnabled = true
}
override fun onAdShow(cAdInfo: CAdInfo?) {
}
override fun onAdDismissed(s: String?) {
}
})
四、展示广告
为了确保播放流程建议在onAdReady回调后调用广告展示并判断isReady状态
if (interstialView!!.isInterstialAdOk) {
interstialView!!.showInterstialAd(this@InterstialActivity)
}
六、销毁广告
protected void onDestroy() {
super.onDestroy();
if (interstialView != null) {
interstialView.onDestroyAd();
}
} // 在加载成功后展示广告
接口说明
AdRequestConfig.Builder()说明
方法名 | 说明 |
slotId(String codeId) | 聚合广告位ID |
AdType(int type) | 广告位类型 |
widthDp(int width) | 设置宽度 dp |
heightDp(int height) | 设置高度 dp |
showDownloadConfirmDialog(boolean isShowDownloadDialog) | 设置是否弹出下载弹框 |
AdViewListener说明
方法名 | 说明 |
onAdClick() | 点击回调 |
onAdShow(CAdInfo var1) | 展示广告 |
onAdReady() | 加载成功回调 |
onAdFailed(String var1) | 加载失败回调 |
onAdDismissed(String var1) | 关闭回调 |
方法名 | 说明 |
void onDestroyAd() | 销毁广告 |
方法名 | 说明 |
int getNetworkFirmId() | 广告网络id |
String getAdsourceId() | 广告源ID |
double getEcpm() | 竞价成功ecpm |
private var InterstialAdCache: Button? = null
private var showInterstialAd: Button? = null
private var showInterstialAd2: Button? = null
private var interstialView: AdView? = null
private var isShowDownloadConfirmDialog = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_interstial)
isShowDownloadConfirmDialog =
SharedPreferencesUtils.getParam(this, "isShowDownloadConfirmDialog", true) as Boolean
InterstialAdCache = findViewById<View>(R.id.InterstialAdCache) as Button
showInterstialAd = findViewById<View>(R.id.showInterstialAd) as Button
showInterstialAd2 = findViewById<View>(R.id.showInterstialAd2) as Button
InterstialAdCache!!.setOnClickListener(View.OnClickListener {
val requestConfig: AdRequestConfig = AdRequestConfig.Builder()
.AdType(AdConfig.AD_TYPE_INTERSTITIAL) //广告样式
.slotId("2323534") //广告场景id
.widthDp(300) //TODO 高度不能自适应,插屏设置的高宽比例需与运营同步(300:300,200:300,300:200)
.heightDp(300)
// .addSougouAdTemplate(AdTemplate.INSERT_IMG_CHARACTER_ID)
.showDownloadConfirmDialog(true)
.build()
val interstialView = AdView(this@InterstialActivity, requestConfig)
interstialView.setInterstialCache { AdSize ->
Toast.makeText(
this@InterstialActivity,
"插屏广告缓存条数:$AdSize", Toast.LENGTH_LONG
).show()
}
})
showInterstialAd2!!.setOnClickListener {
requestAd()
Handler(Looper.getMainLooper()).postDelayed({ finish() }, 200)
}
showInterstialAd!!.setOnClickListener {
if (interstialView != null) {
Log.e("CLOOOUD_", "isRewardVideoOk:" + interstialView!!.isInterstialAdOk)
if (interstialView!!.isInterstialAdOk) {
interstialView!!.showInterstialAd(this@InterstialActivity)
} else {
Toast.makeText(
this@InterstialActivity,
"插屏广告未就绪!",
Toast.LENGTH_LONG
).show()
}
} else {
Log.e("CLOOOUD_", "正在请求插屏广告...")
// 开始请求广告
showInterstialAd!!.text = "正在请求插屏广告..."
showInterstialAd!!.isEnabled = false
requestAd()
}
}
}
private fun requestAd() {
Log.d("cloooudAD", "requestAd "+System.currentTimeMillis())
val requestConfig: AdRequestConfig = AdRequestConfig.Builder()
.AdType(AdConfig.AD_TYPE_INTERSTITIAL) //广告样式
.slotId("2323534") //广告场景id
.widthDp(300)
.heightDp(300)
.showDownloadConfirmDialog(true)
.build()
interstialView = AdView(this, requestConfig)
interstialView!!.setListener(object : AdViewListener {
override fun onAdClick() {
Log.d("CLOOOUDAD", "chapin onAdClick: ")
}
override fun onAdFailed(arg0: String) {
Log.d("CLOOOUDAD", "chapin onAdFailed $arg0")
showInterstialAd?.text = "插屏广告"
showInterstialAd?.isEnabled = true
interstialView?.onDestroyAd()
interstialView = null
Toast.makeText(this@InterstialActivity, arg0, Toast.LENGTH_SHORT).show()
}
override fun onAdReady() {
Log.d("cloooudAD", "onAdReady "+System.currentTimeMillis())
Log.d("CLOOOUDAD", "chapin onAdReady")
showInterstialAd?.text = "点击展示插屏广告"
showInterstialAd?.isEnabled = true
}
override fun onAdShow(cAdInfo: CAdInfo?) {
Log.e("CLOOOUD_POLY", "ecpm: " + cAdInfo?.ecpm)
Log.d("CLOOOUDAD", "chapin onAdShow")
}
override fun onAdDismissed(s: String?) {
Log.d("CLOOOUDAD", "chapin onAdDismissed")
}
})
}
override fun onPause() {
super.onPause()
}
override fun onDestroy() {
interstialView?.onDestroyAd()
super.onDestroy()
}
}