📜 ⬆️ ⬇️

Marmalade SDK. Integration with AdMob, Chartboost, Inmobi and Leadbolt advertising services on iOS and Android platforms

Connecting extensions to the project


In this article, I will explain how to connect interstitial banners of several advertising services for mobile applications developed in the Marmalade SDK environment.
So, we believe that you have already read the Marmalade documentation on connecting the listed services, and also have accounts on the following sites and have registered your applications there:

When registering an application, the system assigns to it a certain identifier (or a pair of identifiers - as was done in Chartboost), which will identify your applications when interacting with advertising services.

Today I use Marmalade SDK version 7.8.0p3 [439542]. The assembly already contains the following extensions of interest to us:

Extensions for Leadbolt are not included in the standard distribution. The Marmalade documentation recommends downloading them from help.leadbolt.com . Unlike AdMob, Inmobi and Chartboost, Leadbolt provides separate extensions for Android and iOS. These extensions are not written in the most convenient way, namely, some functions in them are called the same, which leads to collisions when trying to connect two extensions to one project at once. Therefore, I rewrote the iOS extensions a bit by myself, adding the iOS suffix to all methods where necessary to avoid collisions. The extensions I use are available at github github.com/akk0rd87/Marmalade-Leabolt-SDK . Download them and copy to / extensions / to get it

% Sdk install folder% / extensions / AppTrackerAndroid
% Sdk install folder% / extensions / AppTrackerIOS
')
We include our extensions into the subprojects section of the mkb file:
Subprojects { ... s3eInMobiAds s3eGoogleAdMob s3eChartBoost AppTrackerAndroid AppTrackeriOS } 

In the deployment section, we add the AppTracker.jar link (by default it is located in AppTrackerAndroid, I brought it to the common / jar folder) and Chartboost identifiers for the Anrdoid application:
 deployment { ... # THIS NEED FOR LEADBOLT ON ANDROID android-external-jars='../common/jar/AppTracker.jar' android-extra-strings='(gps_app_id,0), (chartboost_appid, *********),(chartboost_appsig, ***************)' } 


Application interaction with advertising service


The general principle of the application interaction with the advertising service:

From the above principle, the following session states follow, described in adengine_constants.h
 #define AD_ENGINE_TEMPORARY 0 //   .  callback-a; #define AD_ENGINE_NOT_INITED 1 //    #define AD_ENGINE_INITED 2 //  ; #define AD_ENGINE_LOAD_OK 3 //    ; #define AD_ENGINE_LOAD_ERR 4 //     ; #define AD_ENGINE_SHOW_OK 5 //      ; #define AD_ENGINE_TERMINATED 6 //  ; 


CPP file for each extension


We include files in which the logic of interaction with a specific advertising service is described. We connect two files for Leadbolt: separately for iOS and Android, since we have separate extensions for these OSs. Also connect the file adengine.cpp, which will manage this logic. Also, do not forget to create the appropriate .h-headers, which will describe the corresponding API functions. In fact, adengine.cpp is my advertising engine, and I use it in several applications. In order not to hardcoding application identifiers in it, for this purpose in each project I additionally include the local.cpp file, which has its own implementation for each individual application.
Files section of the mkb file:
 { ... adengine.cpp googleadmob.cpp inmobi.cpp leadbolt_ios.cpp leadbolt_android.cpp charboost.cpp local.cpp } 
googleadmob.cpp
 #include "s3eGoogleAdMob.h" #include "adengine_constants.h" int googlead_mob_status = AD_ENGINE_NOT_INITED; s3eGoogleAdMobId m_Id = 0; void DestroyAdMobAd() { s3eResult res = s3eGoogleAdMobDestroyAd(m_Id); } static int32 onAdMobLoad(void* systemData, void* userData) { googlead_mob_status = AD_ENGINE_LOAD_OK; return 0; } static int32 onAdMobAction(void* systemData, void* userData) { DestroyAdMobAd(); googlead_mob_status = AD_ENGINE_INITED; return 0; } static int32 onAdMobError(void* systemData, void* userData) { DestroyAdMobAd(); googlead_mob_status = AD_ENGINE_LOAD_ERR; return 0; } static int32 onAdMobFiledToLoad(void* systemData, void* userData) { DestroyAdMobAd(); googlead_mob_status = AD_ENGINE_LOAD_ERR; return 0; } //////////////////////////////////////////// //////// API //////////////////////////////////////////// void AdMob_Init(char AppCode[]) { s3eGoogleAdMobRegister(S3E_GOOGLEADMOB_CALLBACK_AD_LOADED, onAdMobLoad , NULL); s3eGoogleAdMobRegister(S3E_GOOGLEADMOB_CALLBACK_AD_ACTION, onAdMobAction, NULL); s3eGoogleAdMobRegister(S3E_GOOGLEADMOB_CALLBACK_AD_ERROR , onAdMobError , NULL); s3eResult res0 = s3eGoogleAdMobSetAdUnitId(AppCode, S3E_TRUE); googlead_mob_status = AD_ENGINE_INITED; } void AdMob_Load() { googlead_mob_status = AD_ENGINE_TEMPORARY; s3eResult res1 = s3eGoogleAdMobPrepareAd(&m_Id); s3eGoogleAdMobAdInfo info; s3eGoogleAdMobInspectAd(m_Id, &info); s3eResult res2 = s3eGoogleAdMobLoadInterstitialAd(m_Id); } void AdMob_Show() { googlead_mob_status = AD_ENGINE_TEMPORARY; s3eResult res = s3eGoogleAdMobShowAd(m_Id); } void AdMob_Terminate() { DestroyAdMobAd(); googlead_mob_status = AD_ENGINE_TERMINATED; s3eGoogleAdMobUnRegister(S3E_GOOGLEADMOB_CALLBACK_AD_LOADED, onAdMobLoad ); s3eGoogleAdMobUnRegister(S3E_GOOGLEADMOB_CALLBACK_AD_ACTION, onAdMobAction); s3eGoogleAdMobUnRegister(S3E_GOOGLEADMOB_CALLBACK_AD_ERROR , onAdMobError ); } int AdMob_Status() { return googlead_mob_status; } s3eBool AdMob_Avaliable() { return s3eGoogleAdMobAvailable(); } 


inmobi.cpp
 #include "s3eInMobiAds.h" #include "s3e.h" #include "adengine_constants.h" int InMobi_ad_state = AD_ENGINE_NOT_INITED; static int int_request_completed(void *systemData, void *userData) { InMobi_ad_state = AD_ENGINE_LOAD_OK; return S3E_RESULT_SUCCESS; } static int int_request_failed(void *systemData, void *userData) { InMobi_ad_state = AD_ENGINE_LOAD_ERR; return S3E_RESULT_SUCCESS; } static int int_show_adscreen(void *systemData, void *userData) { return S3E_RESULT_SUCCESS; } static int int_dismiss_adscreen(void *systemData, void *userData) { InMobi_ad_state = AD_ENGINE_INITED; return S3E_RESULT_SUCCESS; } static int int_leave_application(void *systemData, void *userData) { InMobi_ad_state = AD_ENGINE_INITED; return S3E_RESULT_SUCCESS; } static int int_ad_interacted(void *systemData, void *userData) { InMobi_ad_state = AD_ENGINE_INITED; return S3E_RESULT_SUCCESS; } static int DeviceStateChangeCallback(void *systemData, void *userData) { InMobi_ad_state = AD_ENGINE_INITED; return S3E_RESULT_SUCCESS; } void InMobi_Init(char appcode[50]) { InMobiAdsRegisterIntCallback(INMOBIADS_CALLBACK_INT_REQUEST_COMPLETED, int_request_completed, NULL); InMobiAdsRegisterIntCallback(INMOBIADS_CALLBACK_INT_REQUEST_FAILED, int_request_failed, NULL); InMobiAdsRegisterIntCallback(INMOBIADS_CALLBACK_INT_SHOW_ADSCREEN, int_show_adscreen, NULL); InMobiAdsRegisterIntCallback(INMOBIADS_CALLBACK_INT_DISMISS_ADSCREEN, int_dismiss_adscreen, NULL); InMobiAdsRegisterIntCallback(INMOBIADS_CALLBACK_INT_LEAVE_APPLICATION, int_leave_application, NULL); InMobiAdsRegisterIntCallback(INMOBIADS_CALLBACK_INT_INTERACTED, int_ad_interacted, NULL); s3eDeviceRegister(S3E_DEVICE_UNPAUSE, DeviceStateChangeCallback, NULL); inmobi_initialize(appcode); inmobi_interstitial_init(appcode); InMobi_ad_state = AD_ENGINE_INITED; } void InMobi_Load() { InMobi_ad_state = AD_ENGINE_TEMPORARY; inmobi_interstitial_load(""); } void InMobi_Show() { InMobi_ad_state = AD_ENGINE_TEMPORARY; inmobi_interstitial_show(); } void InMobi_Release() { InMobi_ad_state = AD_ENGINE_TERMINATED; inmobi_interstitial_release(); InMobiAdsUnRegisterIntCallback(INMOBIADS_CALLBACK_INT_REQUEST_COMPLETED, int_request_completed); InMobiAdsUnRegisterIntCallback(INMOBIADS_CALLBACK_INT_REQUEST_FAILED, int_request_failed); InMobiAdsUnRegisterIntCallback(INMOBIADS_CALLBACK_INT_SHOW_ADSCREEN, int_show_adscreen); InMobiAdsUnRegisterIntCallback(INMOBIADS_CALLBACK_INT_DISMISS_ADSCREEN, int_dismiss_adscreen); InMobiAdsUnRegisterIntCallback(INMOBIADS_CALLBACK_INT_LEAVE_APPLICATION, int_leave_application); InMobiAdsUnRegisterIntCallback(INMOBIADS_CALLBACK_INT_INTERACTED, int_ad_interacted); s3eDeviceUnRegister(S3E_DEVICE_UNPAUSE, DeviceStateChangeCallback); } int InMobi_Status() { return InMobi_ad_state; } s3eBool InMobi_Avaliable() { return s3eInMobiAdsAvailable(); } 


leadbolt_ios.cpp
 #include "AppTrackeriOS.h" #include "adengine_constants.h" int ldb_ios_ad_state = AD_ENGINE_NOT_INITED; void LBD_IOS_DoDestroy() { AppTrackeriOS_destroyModule(); } int32 LBD_IOS_onModuleFailedEvent(void* system, void* user){ ldb_ios_ad_state = AD_ENGINE_LOAD_ERR; return 0; } int32 LBD_IOS_onModuleClosedEvent(void* system, void* user){ LBD_IOS_DoDestroy(); ldb_ios_ad_state = AD_ENGINE_INITED; return 0; } int32 LBD_IOS_onModuleClickedEvent(void* system, void* user){ return 0; } int32 LBD_IOS_onModuleLoadedEvent(void* system, void* user){ ldb_ios_ad_state = AD_ENGINE_SHOW_OK; return 0; } int32 LBD_IOS_onModuleCacheEvent(void* system, void* user){ ldb_ios_ad_state = AD_ENGINE_LOAD_OK; return 0; } int32 LBD_IOS_onMediaFinishedEvent(void* system, void* user){ LBD_IOS_DoDestroy(); ldb_ios_ad_state = AD_ENGINE_INITED; return 0; } ///////////////////////////////////////////// ///////// API ///////////////////////////////////////////// int LDB_IOS_Status() { return ldb_ios_ad_state; } void LDB_IOS_Init(char AppCode[]) { AppTrackeriOSRegister(APPTRACKERIOS_MODULEFAILED, &LBD_IOS_onModuleFailedEvent, NULL); AppTrackeriOSRegister(APPTRACKERIOS_MODULELOADED, &LBD_IOS_onModuleLoadedEvent, NULL); AppTrackeriOSRegister(APPTRACKERIOS_MODULECLOSED, &LBD_IOS_onModuleClosedEvent, NULL); AppTrackeriOSRegister(APPTRACKERIOS_MODULECLICKED, &LBD_IOS_onModuleClickedEvent, NULL); AppTrackeriOSRegister(APPTRACKERIOS_MODULECACHED, &LBD_IOS_onModuleCacheEvent, NULL); AppTrackeriOSRegister(APPTRACKERIOS_MEDIAFINISHED, &LBD_IOS_onMediaFinishedEvent, NULL); AppTrackeriOS_startSession(AppCode); ldb_ios_ad_state = AD_ENGINE_INITED; } void LDB_IOS_Load() { ldb_ios_ad_state = AD_ENGINE_TEMPORARY; AppTrackeriOS_loadModuleToCache("inapp"); } void LDB_IOS_Show() { ldb_ios_ad_state = AD_ENGINE_TEMPORARY; AppTrackeriOS_loadModule("inapp"); } void LDB_IOS_Terminate() { ldb_ios_ad_state = AD_ENGINE_TERMINATED; AppTrackeriOS_closeSession(); AppTrackeriOSUnRegister(APPTRACKERIOS_MODULEFAILED, &LBD_IOS_onModuleFailedEvent); AppTrackeriOSUnRegister(APPTRACKERIOS_MODULELOADED, &LBD_IOS_onModuleLoadedEvent); AppTrackeriOSUnRegister(APPTRACKERIOS_MODULECLOSED, &LBD_IOS_onModuleClosedEvent); AppTrackeriOSUnRegister(APPTRACKERIOS_MODULECLICKED, &LBD_IOS_onModuleClickedEvent); AppTrackeriOSUnRegister(APPTRACKERIOS_MODULECACHED, &LBD_IOS_onModuleCacheEvent); AppTrackeriOSUnRegister(APPTRACKERIOS_MEDIAFINISHED, &LBD_IOS_onMediaFinishedEvent); } s3eBool LDB_IOS_Avaliable() { return AppTrackeriOSAvailable(); } 


leadbolt_android.cpp
 #include "AppTrackerAndroid.h" #include "adengine_constants.h" int ldb_ad_state = AD_ENGINE_NOT_INITED; void DoDestroy() { destroyModule(); } int32 onModuleFailedEvent(void* system, void* user){ ldb_ad_state = AD_ENGINE_LOAD_ERR; return 0; } int32 onModuleClosedEvent(void* system, void* user){ DoDestroy(); ldb_ad_state = AD_ENGINE_INITED; return 0; } int32 onModuleClickedEvent(void* system, void* user){ return 0; } int32 onModuleLoadedEvent(void* system, void* user){ ldb_ad_state = AD_ENGINE_SHOW_OK; return 0; } int32 onModuleCacheEvent(void* system, void* user){ ldb_ad_state = AD_ENGINE_LOAD_OK; return 0; } int32 onMediaFinishedEvent(void* system, void* user){ DoDestroy(); ldb_ad_state = AD_ENGINE_INITED; return 0; } ///////////////////////////////////////////// ///////// API ///////////////////////////////////////////// int LDB_Android_Status() { return ldb_ad_state; } void LDB_Android_Init(char AppCode[]) { AppTrackerAndroidRegister(APPTRACKERANDROID_MODULEFAILED , &onModuleFailedEvent , NULL); AppTrackerAndroidRegister(APPTRACKERANDROID_MODULELOADED , &onModuleLoadedEvent , NULL); AppTrackerAndroidRegister(APPTRACKERANDROID_MODULECLOSED , &onModuleClosedEvent , NULL); AppTrackerAndroidRegister(APPTRACKERANDROID_MODULECLICKED, &onModuleClickedEvent, NULL); AppTrackerAndroidRegister(APPTRACKERANDROID_MODULECACHED , &onModuleCacheEvent , NULL); AppTrackerAndroidRegister(APPTRACKERANDROID_MEDIAFINISHED, &onMediaFinishedEvent, NULL); startSession(AppCode); ldb_ad_state = AD_ENGINE_INITED; } void LDB_Android_Load() { ldb_ad_state = AD_ENGINE_TEMPORARY; loadModuleToCache("inapp", ""); } void LDB_Android_Show() { ldb_ad_state = AD_ENGINE_TEMPORARY; loadModule("inapp", ""); } void LDB_Android_Terminate() { ldb_ad_state = AD_ENGINE_TERMINATED; closeSession(); AppTrackerAndroidUnRegister(APPTRACKERANDROID_MODULEFAILED , &onModuleFailedEvent); AppTrackerAndroidUnRegister(APPTRACKERANDROID_MODULELOADED , &onModuleLoadedEvent); AppTrackerAndroidUnRegister(APPTRACKERANDROID_MODULECLOSED , &onModuleClosedEvent); AppTrackerAndroidUnRegister(APPTRACKERANDROID_MODULECLICKED, &onModuleClickedEvent); AppTrackerAndroidUnRegister(APPTRACKERANDROID_MODULECACHED , &onModuleCacheEvent); AppTrackerAndroidUnRegister(APPTRACKERANDROID_MEDIAFINISHED, &onMediaFinishedEvent); } s3eBool LDB_Android_Avaliable() { return AppTrackerAndroidAvailable(); } 


charboost.cpp
 #include "s3e.h" #include "s3eChartBoost.h" #include "adengine_constants.h" int charboost_ad_state = AD_ENGINE_NOT_INITED; void RequestCB(void* systemData, void* userData) { charboost_ad_state = AD_ENGINE_LOAD_OK; } void AdvertisementClosed(void* System, void* User) { charboost_ad_state = AD_ENGINE_INITED; } void AdvertisementDismissed(void* System, void* User) { charboost_ad_state = AD_ENGINE_INITED; } void AdvertisementClicked(void* System, void* User) { charboost_ad_state = AD_ENGINE_INITED; } void ErrorCallback(void* System, void* User) { charboost_ad_state = AD_ENGINE_LOAD_ERR; } ////////////////////////////// //////////////// API ////////////////////////////// s3eBool CharBoost_Avaliable() { return s3eChartBoostAvailable(); } void CharBoost_Init(char AppCode[], char Signature[]) { s3eChartBoostRegister(S3E_CHARTBOOST_CALLBACK_REQUEST_RESPONSE, (s3eCallback) RequestCB , NULL); s3eChartBoostRegister(S3E_CHARTBOOST_CALLBACK_AD_CLOSED , (s3eCallback) AdvertisementClosed , NULL); s3eChartBoostRegister(S3E_CHARTBOOST_CALLBACK_AD_DISMISSED , (s3eCallback) AdvertisementDismissed, NULL); s3eChartBoostRegister(S3E_CHARTBOOST_CALLBACK_AD_CLICKED , (s3eCallback) AdvertisementClicked , NULL); s3eChartBoostRegister(S3E_CHARTBOOST_CALLBACK_ERROR , (s3eCallback) ErrorCallback , NULL); s3eChartBoostSetAppID(AppCode); s3eChartBoostSetAppSignature(Signature); s3eChartBoostStartSession(); charboost_ad_state = AD_ENGINE_INITED; } void CharBoost_Load() { charboost_ad_state = AD_ENGINE_LOAD_OK; } void CharBoost_Show() { charboost_ad_state = AD_ENGINE_TEMPORARY; s3eChartBoostShowInterstitial(S3E_CHARTBOOST_LOCATION(HOME_SCREEN)); } void CharBoost_Terminate() { charboost_ad_state = AD_ENGINE_TERMINATED; s3eChartBoostUnRegister( S3E_CHARTBOOST_CALLBACK_REQUEST_RESPONSE, (s3eCallback)RequestCB); s3eChartBoostUnRegister( S3E_CHARTBOOST_CALLBACK_AD_CLOSED, (s3eCallback)AdvertisementClosed); s3eChartBoostUnRegister( S3E_CHARTBOOST_CALLBACK_AD_DISMISSED, (s3eCallback)AdvertisementDismissed); s3eChartBoostUnRegister( S3E_CHARTBOOST_CALLBACK_AD_CLICKED,(s3eCallback) AdvertisementClicked); s3eChartBoostUnRegister(S3E_CHARTBOOST_CALLBACK_ERROR, (s3eCallback)ErrorCallback); } int CharBoost_Status() { return charboost_ad_state; } 


local.cpp - application identifiers are masked
 #include <string.h> #include "s3e.h" void GetInMobiAppAdIdentifier(char code[]) { int os = s3eDeviceGetInt(S3E_DEVICE_OS); switch (os) { case S3E_OS_ID_ANDROID: strcpy(code, "********************************"); break; case S3E_OS_ID_IPHONE: strcpy(code, "********************************"); break; // case S3E_OS_ID_WINDOWS: // break; } } void GetLDBAppAdIdentifier(char code[]) { int os = s3eDeviceGetInt(S3E_DEVICE_OS); switch (os) { case S3E_OS_ID_ANDROID: strcpy(code, "********************************"); break; case S3E_OS_ID_IPHONE: strcpy(code, "********************************"); break; // case S3E_OS_ID_WINDOWS: // break; } } void GetCharBoostIdentifiers (char app[], char signature[]) { int os = s3eDeviceGetInt(S3E_DEVICE_OS); switch (os) { case S3E_OS_ID_ANDROID: strcpy(app , "************************"); strcpy(signature, "****************************************"); break; case S3E_OS_ID_IPHONE: strcpy(app , "************************"); strcpy(signature, "****************************************"); break; // case S3E_OS_ID_WINDOWS: // break; } } void GetAdMobAdIdentifier(char code[]) { int os = s3eDeviceGetInt(S3E_DEVICE_OS); switch (os) { case S3E_OS_ID_ANDROID: strcpy(code, "ca-app-pub-***************************"); break; case S3E_OS_ID_IPHONE: strcpy(code, "ca-app-pub-***************************"); break; // case S3E_OS_ID_WINDOWS: // break; } } 


AdEngine - Application API


By testing it was revealed (and a confirmation was found on the answers.madewithmarmalade.com ) that the ChartBoost-API does not actually call Callbacks - this is a bug. Concerning:

The logic of the advertising engine is:
- some time before the intended time of the advertisement being shown by requesting the banner to be cached until a banner is cached by at least one of the services;
- at the moment when you need to show advertising, from those services for which something has been cached, we select the most priority one and show its banner.
- if none of the services have been cached, then we call the ChartBoost banner display method. Will the display of advertising in this case - here as lucky.
adengine.cpp
 #include "local.h" #include "s3e.h" #include "inmobi.h" #include "leadbolt_ios.h" #include "leadbolt_android.h" #include "googleadmob.h" #include "charboost.h" #define DELAY_MS 1000 //        ( ) #define DELAY_4_SHOW_MS 60000 // 1 minute.      //       (   ) int64 InMobiPrevTm, LDB_AndroidPrevTm, LDB_IOSPrevTm, CharBoostPrevTm, AdMobPrevTm; int64 LastShowTm; //     struct Struct_AdAvaliable { s3eBool InMobi; s3eBool LeadBolt_Android; s3eBool LeadBolt_IOS; s3eBool CharBoost; s3eBool AdMob; }; Struct_AdAvaliable AdAvaliable; ///////////////////////////////////////////////// /////////////////// API ///////////////////////////////////////////////// void AdEngine_Init() { char AppCode [50]; char Signature[50]; AdAvaliable.InMobi = S3E_FALSE; AdAvaliable.LeadBolt_Android = S3E_FALSE; AdAvaliable.LeadBolt_IOS = S3E_FALSE; AdAvaliable.CharBoost = S3E_FALSE; AdAvaliable.AdMob = S3E_FALSE; InMobiPrevTm = 0; LDB_AndroidPrevTm = 0; CharBoostPrevTm = 0; AdMobPrevTm = 0; LDB_IOSPrevTm = 0; LastShowTm = 0; AdAvaliable.LeadBolt_Android = LDB_Android_Avaliable(); AdAvaliable.LeadBolt_IOS = LDB_IOS_Avaliable(); AdAvaliable.InMobi = InMobi_Avaliable(); AdAvaliable.CharBoost = CharBoost_Avaliable(); AdAvaliable.AdMob = AdMob_Avaliable(); if (AdAvaliable.AdMob) { GetAdMobAdIdentifier(AppCode); //     local.cpp AdMob_Init(AppCode); } if (AdAvaliable.InMobi) { GetInMobiAppAdIdentifier(AppCode); //     local.cpp InMobi_Init(AppCode); } if (AdAvaliable.LeadBolt_Android) { GetLDBAppAdIdentifier(AppCode); //     local.cpp LDB_Android_Init(AppCode); } if (AdAvaliable.LeadBolt_IOS) { GetLDBAppAdIdentifier(AppCode); //     local.cpp LDB_IOS_Init(AppCode); } if (AdAvaliable.CharBoost) { GetCharBoostIdentifiers(AppCode, Signature); //     local.cpp CharBoost_Init(AppCode, Signature); } } void AdEngine_Load() //    { int status; int64 NewTm; NewTm = s3eTimerGetMs(); if (AdAvaliable.AdMob == S3E_TRUE) { status = AdMob_Status(); switch (status) { case AD_ENGINE_INITED: AdMob_Load(); break; case AD_ENGINE_LOAD_ERR: if (NewTm - AdMobPrevTm > DELAY_MS) { AdMobPrevTm = NewTm; AdMob_Load(); } break; case AD_ENGINE_LOAD_OK: return; //    AdMob -  } } if (AdAvaliable.InMobi == S3E_TRUE) { status = InMobi_Status(); switch (status) { case AD_ENGINE_INITED: InMobi_Load(); break; case AD_ENGINE_LOAD_ERR: if (NewTm - InMobiPrevTm > DELAY_MS) { InMobiPrevTm = NewTm; InMobi_Load(); } break; case AD_ENGINE_LOAD_OK: return; } } if (AdAvaliable.LeadBolt_IOS == S3E_TRUE) { status = LDB_IOS_Status(); switch (status) { case AD_ENGINE_INITED: LDB_IOS_Load(); break; case AD_ENGINE_LOAD_ERR: if (NewTm - LDB_IOSPrevTm > DELAY_MS) { LDB_IOSPrevTm = NewTm; LDB_IOS_Load(); } break; case AD_ENGINE_LOAD_OK: return; } } if (AdAvaliable.LeadBolt_Android == S3E_TRUE) { status = LDB_Android_Status(); switch (status) { case AD_ENGINE_INITED: LDB_Android_Load(); break; case AD_ENGINE_LOAD_ERR: if (NewTm - LDB_AndroidPrevTm > DELAY_MS) { LDB_AndroidPrevTm = NewTm; LDB_Android_Load(); } break; case AD_ENGINE_LOAD_OK: return; } } //  AdAvaliable.CharBoost,    Callback-   /* if (AdAvaliable.CharBoost) { status = CharBoost_Status(); switch (status) { case AD_ENGINE_INITED: CharBoost_Load(); break; case AD_ENGINE_LOAD_ERR: if (NewTm - CharBoostPrevTm > DELAY_MS) { CharBoostPrevTm = NewTm; CharBoost_Load(); } break; } } */ } bool AdEngine_Show() //      { int status; int64 NewTm = s3eTimerGetMs(); //          if ((NewTm - LastShowTm) < DELAY_4_SHOW_MS && LastShowTm != 0) return true; if (AdAvaliable.AdMob) { status = AdMob_Status(); if (status == AD_ENGINE_LOAD_OK) { AdMob_Show(); LastShowTm = s3eTimerGetMs(); return true; } } if (AdAvaliable.LeadBolt_IOS) { status = LDB_IOS_Status(); if (status == AD_ENGINE_LOAD_OK) { LDB_IOS_Show(); LastShowTm = s3eTimerGetMs(); return true; } } if (AdAvaliable.LeadBolt_Android) { status = LDB_Android_Status(); if (status == AD_ENGINE_LOAD_OK) { LDB_Android_Show(); LastShowTm = s3eTimerGetMs(); return true; } } if (AdAvaliable.InMobi) { status = InMobi_Status(); if (status == AD_ENGINE_LOAD_OK) { InMobi_Show(); LastShowTm = s3eTimerGetMs(); return true; } } if (AdAvaliable.CharBoost) { CharBoost_Show(); LastShowTm = s3eTimerGetMs(); return true; } return false; } void AdEngine_Terminate() { if (AdAvaliable.InMobi) { InMobi_Release(); } if (AdAvaliable.LeadBolt_Android) { LDB_Android_Terminate(); } if (AdAvaliable.LeadBolt_IOS) { LDB_IOS_Terminate(); } if (AdAvaliable.AdMob) { AdMob_Terminate(); } if (AdAvaliable.CharBoost) { CharBoost_Terminate(); } } 



Editing AndroidManifest.xml


Supplement the list of activity
 <!-- inmobi --> <activity android:name="com.inmobi.androidsdk.IMBrowserActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|smallestScreenSize|screenSize" android:theme="@android:style/Theme.Translucent.NoTitleBar"> </activity> <activity android:name="com.inmobi.android.sample.app.AdBannerActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|smallestScreenSize|screenSize" > </activity> <activity android:name="com.inmobi.android.sample.app.AdInterstitialActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|smallestScreenSize|screenSize"> </activity> <service android:name="com.inmobi.commons.internal.ActivityRecognitionManager" android:enabled="true"> </service> <!-- Admob --> <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" /> <meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/gps_app_id" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <!-- CharBoost --> <activity android:name="com.chartboost.sdk.CBImpressionActivity" android:excludeFromRecents="true" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <!-- Leadbolt --> <activity android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:name="com.apptracker.android.module.AppModuleActivity" android:label="ModuleActivity" android:theme="@android:style/Theme.Translucent" > </activity> <!-- Leadbolt. Required for Google Referrer --> <receiver android:name="com.apptracker.android.track.AppTrackerReceiver" android:exported="true"> <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver> 


We fill up the list of permissions
 <!--       --> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <!--       --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!--     Chartboost,     storage.         --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 


Usage scenario




Experience of use


The main distribution territory of my applications is Russia, Ukraine, Kazakhstan and Belarus. There are in other countries, but this percentage is insignificant. As a result of a year of using these services, I refused Inmobi and Leadbolt for the following reasons:

Since ChartBoost has quite good FillRate, I stopped while on a pair of AdMob (as the main service) and ChartBoost (for the case when, by AdMob, the caching request returned an error).
The plans have integration with Appodeal - if everything goes well, then I will definitely add an article.

Source: https://habr.com/ru/post/301716/


All Articles