最简单的原生广告展示方式

时间:2020-04-04 15:41:45

标签: native-ads appodeal

任何人都可以在这里展示如何以最简单的方式展示原生广告的广告吗?

NativeAdViewAppWall =内容网页视图之前,而NativeAdViewContentStream =内容网页视图之后。

谢谢。

1 个答案:

答案 0 :(得分:0)

显示原生广告的简单方法:

xml文件:

 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="70sp"
    android:id="@+id/native_holder"
    ></RelativeLayout>

在onCreate中:

    private List<NativeAd> nativeAds = new ArrayList<>();
    Appodeal.setTesting(true);
    Appodeal.setAutoCache(Appodeal.NATIVE, false);
    Appodeal.initialize(this, "apikey",  Appodeal.NATIVE , true);
    setNaitivAD();

并使用此方法:

private void setNaitivAD(){

    Appodeal.cache(this, Appodeal.NATIVE);
    Appodeal.setNativeCallbacks(new NativeCallbacks() {
        @Override
        public void onNativeLoaded() {
            Toast.makeText(MainActivity.this, "onNativeLoaded!", Toast.LENGTH_SHORT).show();

            nativeAds = Appodeal.getNativeAds(1);
            RelativeLayout holder = (RelativeLayout) findViewById(R.id.native_holder);
            NativeAdViewAppWall nativeAdView = new NativeAdViewAppWall(MainActivity.this, nativeAds.get(0));
            holder.addView(nativeAdView);
        }

        @Override
        public void onNativeFailedToLoad() {
            Toast.makeText(MainActivity.this, "onNativeFailedToLoad", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNativeShown(NativeAd nativeAd) {
            Toast.makeText(MainActivity.this, "onNativeShown", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNativeShowFailed(NativeAd nativeAd) {

        }

        @Override
        public void onNativeClicked(NativeAd nativeAd) {
            Toast.makeText(MainActivity.this, "onNativeClicked", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNativeExpired() {

        }
    });

}