MNG Ads provides functionalities for monetizing your mobile application: from premium sales with rich media, video and innovative formats, it facilitates inserting native mobile ads as well all standard display formats. MngAds SDK is a library that allow you to handle the following Ads servers with the easy way :

Initialize Check

To verify if the SDK is fully initialized you have to call isInitialized():

...importcom.mngads.MNGAdsFactory;importcom.mngads.listener.MNGAdsSDKFactoryListener;...publicclassMainActivityextendsActivityimplementsMNGAdsSDKFactoryListener{...if(MNGAdsFactory.isInitialized()){//The SDK is initializedToast.makeText(this,"MNGAdsFactory is initialized",Toast.LENGTH_SHORT).show();}else{//The SDK is initializing//set up a callback that will be called when is fully initializedMNGAdsFactory.setMNGAdsSDKFactoryListener(this);Toast.makeText(this,"MNGAdsFactory is not initialized",Toast.LENGTH_SHORT).show();}......@OverridepublicvoidonMNGAdsSDKFactoryDidFinishInitializing(){Toast.makeText(this,"MNGAds SDK Factory Did Finish Initializing",Toast.LENGTH_SHORT).show();Log.d(TAG,"MNGAds SDK Factory Did Finish Initializing");}@OverridepublicvoidonMNGAdsSDKFactoryDidFailInitialization(Exceptione){Toast.makeText(this,"MNGAds SDK Factory failed to initialize",Toast.LENGTH_SHORT).show();Log.d(TAG,"MNGAdsSDKFactoryDidFailInitialization: "+e);}@OverridepublicvoidonMNGAdsSDKFactoryDidResetConfig(){Toast.makeText(this,"MNGAds SDK Factory Did Finish Initializing",Toast.LENGTH_SHORT).show();Log.d(TAG,"MNGAds SDK Factory Did Finish Initializing");}...

Note
onMNGAdsSDKFactoryDidFinishInitializing() is called when the the first initialisation finished.
onMNGAdsSDKFactoryDidResetConfig() is called when the sdk configuraiton has been updated and finished reinitialisation.
onMNGAdsSDKFactoryDidFailInitialization() is called when an error occurs during initialisation or configuration update.

Timeout

The time given to the ad view to download the ad data. After this time, the dispacher stops the ad server running (with failure) and move to the next.

Handle callBack from BannerListener

v1.5.1 or above
bannerDidLoad(View adView) changed to bannerDidLoad(View adView,int preferredHeightDP).
bannerDidLoad(View adView,int preferredHeightDP): will be called by the SDK when your bannerView is ready. now you can add your bannerView to your view.

@OverridepublicvoidbannerDidLoad(ViewadView,intpreferredHeightDP);Log.d(TAG,"your banner is ready")...// it's preferable to adjust the ad container view size to match the returned Ad size for a better display...adLayout.addView(adView);}

bannerDidFail(Exception adsException): will be called when all ads servers fail. it will return the error of last called ads server.

Infeed

Init factory

To create an In-Feed Ad format ( the ads that show up in the middle of the stream as you scroll through your content Parallax or Video) you must init an object with type MNGAdsSDKFactory and set the infeedListener, context.

Show Interstitial after return from background

Native Ads

Native ads give you the control to design the perfect ad units for your app. With our Native Ad API, you can determine the look and feel, size and location of your ads. Because you decide how the ads are formatted, ads can fit seamlessly in your application.

Init factory

To create a nativeAd you have to init an object with type MNGAdsSDKFactory and set the nativeListener.

Build Native Ad UI

@OverridepublicvoidnativeObjectDidLoad(MNGNativeObjectnativeObject){...Stringtitle=nativeObject.getTitle();Stringbody=nativeObject.getBody();StringcallToAction=nativeObject.getCallToAction();Stringprice=nativeObject.getPriceText();Bitmapbadge=nativeObject.getBadge();StringiconUrl=nativeObject.getAdIconUrl();StringcoverImageUrl=nativeObject.getAdCoverImageUrl();//to handle impressions and user interactions you have to register your MAdvertiseNativeContainer as your root layout container and your callToActionView view as followingnativeObject.registerViewForInteraction(nativeAdContainerView,nativeAdCallToActionView);...}

Customize Native Ad Badge

You can use a custom badge for the native ad.

@OverridepublicvoidnativeObjectDidLoad(MNGNativeObjectnativeObject){...Bitmapbadge=nativeObject.getBadge(getActivity(),"String to be displayed in the badge");...}

v2.0 or above

You can also integrate video ads into your Native Ad experience. To enable video you must complete the following steps:

Have SDK version 2.0 or later

You have to call setMediaContainer(viewGroup) then the sdk will handle the rendering process ( displaying) the image cover or the media video inside the view group that depends on the ad network result

@OverridepublicvoidnativeObjectDidLoad(MNGNativeObjectnativeObject){...Stringtitle=nativeObject.getTitle();Stringbody=nativeObject.getBody();StringcallToAction=nativeObject.getCallToAction();Stringprice=nativeObject.getPriceText();Bitmapbadge=nativeObject.getBadge();StringiconUrl=nativeObject.getAdIconUrl();// String coverImageUrl=nativeObject.getAdCoverImageUrl();// there is no need to use coverurlnativeObject.setMediaContainer(mediaViewGroup);//to handle impressions and user interactions you have to register your MAdvertiseNativeContainer as your root layout container and your callToActionView view as followingnativeObject.registerViewForInteraction(nativeAdContainerView,nativeAdCallToActionView);...}

Preferences Object

Preferences object is an optional parameter that allow you select ads by user info.
informations that you can set are:

age : age of user

location : geographical position of the user.

language : language of user (ISO code)

gender : gender of user

keyWord : Use free-form key-values when you want to pass targeting values dynamically into an ad tag based on information you collect from your users. You can also use free-form key-values when there are too many possible values to define in advance. Separator in case of multiple entries is ;.

content url : URL for content related to your app (url must be a string which length not exceed 512 caracters).

The sdk is not initialized, you have to call MNGAdsFactory.initialize(context,"your app id");

MAdvertiseRequestCappedException

CAPPED_REQUEST_ERROR = 3

Your request has been capped

Your request is capped, If you are in doubt, check your capping value related to the placement

MAdvertiseLockedPlacementException

LOCKED_PLACEMENT_ERROR = 4

This placement is locked by an other factory

An other factory has loaded an interstitial using this placement, and its no yet displayed

MAdvertiseBusyFactoryException

BUSY_FACTORY_ERROR = 5

Your factory is busy

Your factory is busy by an other request at the moment

MAdvertiseNoAdException

NO_AD_ERROR = 7

No Ad found

Therese no ad to dilver at the moment

MAdvertiseInterstitialCoolDownException

INTERSTITIAL_COOLDOWN_ERROR = 8

Time between last interstitalDisappear and loadInterstital Must be more than 5s

We have defined a minimum time between interstitalDisappear and loadInterstital, this interval is set to 5 second

MAdvertiseAlreadyShownInterstitialException

INTERSTITIAL_ALREADY_SHOWN_ERROR = 9

Other Interstitial is shown

We tolerate only one interstitial to be shown at time

MAdvertiseTimeOutException

TIME_OUT_ERROR = 10

no ad to deliver before time out

Therese no ad to deliver before the specified time out

Handle Exception

If you want to check which exception was invoked, in the didFail callback you have to cast the exception to MAdvertiseException and then use getErrorCode() to get exception code.
Also you can get exception message by calling getMessage().
In the example below we use interstitialDidFail, even you can use this logic in all our didFail callBack(bannerDidFail, infeedDidFail,nativeAdCollectionDidFail and nativeObjectDidFail)

Enabling debug mode

To enbale debug mode you need to set debug mode to true :

...MNGAdsFactory.setDebugModeEnabled(true);...

Configure your Manifest

You need to add the following to AndroidManifest.xml file :

<!--Grants the SDK permission to access approximate location based on cell tower. --><uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/><!--Grants the SDK permission to access a more accurate location based on GPS. --><uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION"/><!-- External storage is used for pre-caching features if available --><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/><!--Grants the SDK permission to create windows using the type TYPE_SYSTEM_ALERT, shown on top of all other apps.--><!--this permission is required for Debug Mode with Gyroscope Sensor.--><uses-permissionandroid:name="android.permission.SYSTEM_ALERT_WINDOW"/><!-- b4s --><uses-sdktools:overrideLibrary="com.ezeeworld.b4s.android.sdk.playservices"/><uses-featureandroid:name="android.hardware.bluetooth_le"android:required="true"/><uses-permissionandroid:name="android.permission.BLUETOOTH"/><uses-permissionandroid:name="android.permission.BLUETOOTH_ADMIN"/><!--This embeds the version of Google Play services that the app was compiled with.. --><meta-dataandroid:name="com.google.android.gms.version"android:value="@integer/google_play_services_version"/>

Eyes tracking

available v2.6

the face tracking feature was implemented to determine wether the user is watching the ad or not , and for how long (in ms). this feature is optional and disabled by default, to enable it you need to :

download umooveVx.aar library and place it in the /libs folder in your project.

edit your build.gradle, add the library :

//face detection umoove
compile(name: 'umooveV2.12.1', ext: 'aar')

you need to declare your flat file repository.

allprojects {
repositories {
jcenter()
flatDir{
dirs 'libs'
}
}
}

and you have to specify abiFilters to avoid some problems with arm64-v8a devices : add abiFilters to your build.gradle like this

defaultConfig
{
.
.
.
ndk {
abiFilters "armeabi-v7a","x86"
}
}

and you need to allow deprecated ndk in your gradle.properties file.

android.useDeprecatedNdk=true

Troubleshooting

android:noHistory="true" : This may remove your acivity when interstitial Ad is displayed