如何在内容之间整合Mopub Native广告 [英] How to integrate Mopub Native ads in between content

查看:197
本文介绍了如何在内容之间整合Mopub Native广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在列表视图中集成了Mopub原生广告,但一切正常,但是我希望在不在列表视图中的内容之间显示原生广告。

I have integrated Mopub native ads in listview all working good but i want to show native ads in between my content not in listview.

我尝试了

MoPubNative.MoPubNativeNetworkListener moPubNativeListener = new MoPubNative.MoPubNativeNetworkListener() {
        @Override
        public void onNativeLoad(NativeAd nativeAd) {
            // ...
        }

        @Override
        public void onNativeFail(NativeErrorCode errorCode) {
            // ...
        }
    };

    MoPubNative moPubNative = new MoPubNative(SingleActivity.this, "ffb8734de73e4d62b93bae99c06db41f", moPubNativeListener);

    ViewBinder viewBinder = new ViewBinder.Builder(R.layout.native_ad_layout)
            .mainImageId(R.id.native_ad_main_image)
            .iconImageId(R.id.native_ad_icon_image)
            .titleId(R.id.native_ad_title)
            .privacyInformationIconImageId(R.id.native_ad_daa_icon_image)
            .textId(R.id.native_ad_text)
            .build();

    MoPubStaticNativeAdRenderer moPubStaticNativeAdRenderer = new MoPubStaticNativeAdRenderer(viewBinder);
    moPubNative.registerAdRenderer(moPubStaticNativeAdRenderer);

    Location exampleLocation = new Location("example_location");
    exampleLocation.setLatitude(23.1);
    exampleLocation.setLongitude(42.1);
    exampleLocation.setAccuracy(100);

    //Specify which native assets you want to use in your ad.
    EnumSet<RequestParameters.NativeAdAsset> assetsSet = EnumSet.of(RequestParameters.NativeAdAsset.TITLE,
            RequestParameters.NativeAdAsset.TEXT,
            RequestParameters.NativeAdAsset.CALL_TO_ACTION_TEXT,
            RequestParameters.NativeAdAsset.ICON_IMAGE);

    RequestParameters requestParameters = new RequestParameters.Builder()
            .keywords("gender:m,age:27")
            .location(exampleLocation)
            .desiredAssets(assetsSet)
            .build();

    moPubNative.makeRequest(requestParameters);

但是您可以看到我正在加载布局

but as you can see i am loading layout

  ViewBinder viewBinder = new ViewBinder.Builder(R.layout.native_ad_layout)

但如何在我的详细信息活动之间呈现此布局。

but how to render this layout in between my content in detail activity.

谢谢。

推荐答案

至少在最新,最出色的MoPub SDK中,这就是做到这一点的方法。

This is the way to do it, at least in latest and greatest MoPub SDK.

    public void onNativeLoad(NativeAd nativeAd) {

        RelativeLayout adParent = findViewById(R.id.ad_holder);
        View adView = nativeAd.createAdView(getActivity(), adParent);
        nativeAd.prepare(adView);
        nativeAd.renderAdView(adView);
        adParent.addView(adView);
    }

这篇关于如何在内容之间整合Mopub Native广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆