Wiki

Clone wiki

mobile.mng-ads.com-mngperf / mopub-adaptor-android

Android Mopub Adapter

It is also possible to use MNGAds SDK with Mopub. Preliminary steps:

1.Create a custom network

  • On your mopub dashboard, create a custom network for instance called MNGMopub

customAdnetwork.png

  • Set the following class name for :
  • Banner : Custom event class : com.mopub.mobileads.MNGMopubBanner and Custom event class data : {"mngads_placement":"/YOUR APP ID/PLACEMENT ID BANNER"}

  • Interstitial : Custom event class : com.mopub.mobileads.MNGMopubInterstitial and Custom event class data : {"mngads_placement":"/YOUR APP ID/PLACEMENT ID INTERSTITIAL"}

  • Native : Custom event class : com.mopub.nativeads.MNGMopubNative and Custom event class data : {"mngads_placement":"/YOUR APP ID/PLACEMENT ID NATIVE"}

customAdnetwork.png

2.Integrate MNG Network in your application project

        Map<String, String> mediatedNetworkConfiguration = new HashMap<>();
        mediatedNetworkConfiguration.put("MNGADS_APP_ID", "YOUR MNG APP ID");

        SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder(adUnitId)
                .withMediatedNetworkConfiguration(MNGAdapterConfiguration.class.toString(), mediatedNetworkConfiguration)
                .build();

        MoPub.initializeSdk(this, sdkConfiguration, null);

3.Initialize your ads

Your settings can be added to mopub using the MNGWrapper that builds a compatible argument to add your placement and your preferences.

...
moPub.setLocalExtras(new MNGWrapper.Builder()
.setPreferences(MNGPreferences)
.build());
...

Interstitials and Banners

You may now use MNGMopub to show interstitials and banners ads the same way it's described in the MoPub Documentation. The adapter code and the setup you did on your Mopub dashboard will allow MNGAds to deliver ads.

Native Ads

In addition to your placement and preferences setup, the mng adapter for mopub provides you with a view binder and a special Mopub renderer that you have to use if you need to display a native ad. Create a new MNGViewBinder according to your layout and register it using the MNGMopubRenderer.

Here's an example :

...
MNGViewBinder viewBinder = new MNGViewBinder.Builder(R.layout.ad_unit)
                .titleId(R.id.native_ad_title)
                .textId(R.id.native_ad_text)
                .mainImageId(R.id.native_ad_main_image)
                .iconImageId(R.id.native_ad_icon_image)
                .badgeImageId(R.id.badgeView)
                .callToActionId(R.id.nativeAdCallToAction)
                .build();

        MNGMopubRenderer renderer = new MNGMopubRenderer(viewBinder);

        moPubNative.registerAdRenderer(renderer);

        moPubNative.makeRequest();
...
Don't forget to set MAdvertiseNativeContainer, which is a used as a simple FrameLayout, as your nativeAd's layout container.

Updated