Wiki
Clone wikimobile.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
- 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"}
2.Integrate MNG Network in your application project
-
Add the mngads Mopub adapter mngads-mopub-adapter-3.0.0.aar and MNG SDK mngads-sdk-x.aar Android SDK to the libs folder of your application project.
-
You have to init MoPub SDK in your application class by adding MNG Network like a Mediated Network.
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(); ...
Updated