带有Appodeal的原生广告

时间:2018-01-31 15:17:37

标签: java kotlin admob appodeal

我对原生广告有些问题。我得到了原生广告的empy列表。这是代码:

Appodeal.setAutoCacheNativeIcons(true)
    Appodeal.setAutoCacheNativeMedia(false)
    Appodeal.initialize(this, apiKey, Appodeal.NATIVE)
    Appodeal.setNativeCallbacks(object : NativeCallbacks {
        override fun onNativeLoaded() {
            Toast.makeText(this@ViewActivity, "onNativeLoaded", Toast.LENGTH_SHORT).show()
        }

        override fun onNativeFailedToLoad() {
            Toast.makeText(this@ViewActivity, "onNativeFailedToLoad", Toast.LENGTH_SHORT).show()
        }

        override fun onNativeShown(nativeAd: NativeAd) {
            Toast.makeText(this@ViewActivity, "onNativeShown", Toast.LENGTH_SHORT).show()
        }

        override fun onNativeClicked(nativeAd: NativeAd) {
            Toast.makeText(this@ViewActivity, "onNativeClicked", Toast.LENGTH_SHORT).show()
        }
    })

    val list = Appodeal.getNativeAds(5)
    nativeAd.getProviderView(this)

    Toast.makeText(this@ViewActivity, "size = "  + list.size , Toast.LENGTH_SHORT).show()

所以每次我得到list.size等于0.我做错了什么?

1 个答案:

答案 0 :(得分:1)

在使用autocache方法初始化sdk之前禁用Appodeal.setAutoCache(Appodeal.NATIVE, false);

之后,需要在初始化Appodeal.cache(this, Appodeal.NATIVE, 5);

后使用缓存方法sdk

简单的例子:

Appodeal.setAutoCache(Appodeal.NATIVE, false);
Appodeal.initialize(this, tools.appodealApiKey, Appodeal.NATIVE)
Appodeal.cache(this, Appodeal.NATIVE, 5);

并将Appodeal.getNativeAds(5);等移至onNativeLoaded()回调。 显示缓存广告后,需要再次使用缓存方法