Android Tutorial AdMob Mediation (with InMobi)

AdMob supports ads mediation. This means that the ad can come from different ad networks and not just from Google AdMob network.

It can improve the fill rate and the revenue earned.

upload_2016-9-26_16-13-44.png


You should first start with the standard FirebaseAdMob implementation: https://www.b4x.com/android/forum/threads/67710/#content
Once it works you can continue with adding support for more networks.

Overall it is quite simple to add this feature. The most important tips:

1. Monitor the unfiltered logs (you must use USB debug mode for this) to see any errors.
2. It takes several hours for changes to be applied.

The steps required to add support for a network that is supported by AdMob (list of supported networks):
1. Register with the network.
2. Follow their specific instructions. You will need to add some declarations with the manifest editor.
In the case of InMobi: https://support.inmobi.com/monetize/mediation-guidelines/admob/android-admob-guidelines
B4X:
AddApplicationText(
<activity
android:name="com.inmobi.rendering.InMobiAdActivity"
android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize"
android:hardwareAccelerated="true" />
)
Check the generated Objects\AndroidManifest.xml file if you are not sure whether you added it correctly or not.

3. You will need to download the network SDK and adapter jar, copy them to the additional libraries folder and add a reference to those libraries in your project. For example:
B4X:
#AdditionalJar: libadapterinmobi
#AdditionalJar: InMobi-5.3.1
4. The additional source should be listed in AdMob under the unit:

SS-2016-09-26_16.28.27.png


That's all. The code itself is exactly the same.
 

sorex

Expert
Licensed User
Longtime User
I have been testing this again...

I notice that the APK is about the same size as the admob only one.

while the inmodi jar is 600Kb shouldn't it grow by 600K then?

when I look at the apk contents the only (non-binary) difference I see is that the admobi mediation one has a src.zip in the root with an admob wrapper file but nothing mentioned about inmobi either.


Edit: I notice that the classes.dex file is 900K bigger but due to the zipping the difference is only 50Kb or so.

still didn't see an ad like in Erel's first post tho.
 
Last edited:

sorex

Expert
Licensed User
Longtime User
Same here.. still pending

check your login settings, overhere the password was gone.

click the cog/wheel next to the questionmark at the top right of the admob site
then click ad network optimization setting
edit the inmobi one
fill in the password again if it's gone.

overhere when I look again the password is there but when I look at other pages and then again at the account the password is gone again.

I contact admob about this and asked if it is normal behaviour or a password trashing bug somewhere. I'll let you know when I get an answer.
 

sorex

Expert
Licensed User
Longtime User
@Erel,

that adapter jar is that also working with the v6.0 sdk jar?

that's what I'm using as that was the latest.
 

sorex

Expert
Licensed User
Longtime User
the problem is that admob always spits out own ads for me so it's hard to check.

I created another placement id for an app that has almost no users so I can force inmobi to be the one that pulls ads with your $10 trick.

Need to wait a few hours before the mediation becomes active and then I can check the logs as you mentioned.
 

sorex

Expert
Licensed User
Longtime User
does mediation rely on google play services while firebase admob ads don't?

I see the mediation request in admob but with 0 impression fill.

It was also an ad that shows up regulary via admob.

the log doesn't mention a real error besides the play stuff

B4X:
Trying mediation network: https://googleads.g.doubleclick.net/aclk?sa=L&ai=CgqrgJ5UAWNLiNKPgzAbPjIKwAfnJ2qYF0e-FupIBABAIIM6DkSZgufjKgOQBqQIAAAAAgIQuQagDAaoEIE_QJs6iN6Tb-J4u6CIKYDSWTwGx6Si3mIda2VTgFcfPwAYLgAeB-KkwmAcB&num=1&cid=CAASBORoIi4&sig=AOD64_3Je5HiIMG8FbEn37TPeGDUKp11KQ&adurl=http://example.com
Instantiating mediation adapter: com.google.ads.mediation.inmobi.InMobiAdapter
Trying mediation network:
Instantiating mediation adapter: com.google.ads.mediation.admob.AdMobAdapter
Server parameters: {"gwhirl_share_location":"1","pubid":"ca-app-pub-54xxxxxxxxx\/808844xxx\/cak=no_cache&cadc=wb&caqid=J5UAWLbkM4-DzAa4y7joBw"}
Google Play Store is missing.
Starting ad request.
Use AdRequest.Builder.addTestDevice("A57D1777A59C1XXXXXX2A4E6CC078C") to get test ads on this device.
Ad finished loading.
Ad finished loading.
ad loaded
Could not open '/sys/class/power_supply/genymotion_fake_path/present'
yes display ad
START {flg=0x10080000 cmp=sorex.CLAUStrophobia/com.google.android.gms.ads.AdActivity (has extras) u=0} from pid 1834
readFully was waiting for 764896 bytes, got 16192
readFully was waiting for 748704 bytes, got 16192
readFully was waiting for 732512 bytes, got 16192
readFully was waiting for 716320 bytes, got 16192
readFully was waiting for 700128 bytes, got 16192
readFully was waiting for 683936 bytes, got 16192
readFully was waiting for 667744 bytes, got 16192
readFully was waiting for 651552 bytes, got 16192
readFully was waiting for 635360 bytes, got 16192
readFully was waiting for 619168 bytes, got 16192
readFully was waiting for 602976 bytes, got 16192
readFully was waiting for 586784 bytes, got 16192
readFully was waiting for 570592 bytes, got 16192
readFully was waiting for 554400 bytes, got 16192
readFully was waiting for 538208 bytes, got 16192
readFully was waiting for 522016 bytes, got 16192
readFully was waiting for 505824 bytes, got 16192
readFully was waiting for 489632 bytes, got 16192
readFully was waiting for 473440 bytes, got 16192
readFully was waiting for 457248 bytes, got 16192
readFully was waiting for 441056 bytes, got 16192
readFully was waiting for 424864 bytes, got 16192
readFully was waiting for 408672 bytes, got 16192
readFully was waiting for 392480 bytes, got 16192
readFully was waiting for 376288 bytes, got 9972
readFully was waiting for 366316 bytes, got 16192
readFully was waiting for 350124 bytes, got 16192
readFully was waiting for 333932 bytes, got 16192
readFully was waiting for 317740 bytes, got 16192
readFully was waiting for 301548 bytes, got 16192
readFully was waiting for 285356 bytes, got 16192
readFully was waiting for 269164 bytes, got 16192
readFully was waiting for 252972 bytes, got 16192
readFully was waiting for 236780 bytes, got 16192
readFully was waiting for 220588 bytes, got 16192
readFully was waiting for 204396 bytes, got 16192
readFully was waiting for 188204 bytes, got 16192
readFully was waiting for 172012 bytes, got 16192
readFully was waiting for 155820 bytes, got 16192
readFully was waiting for 139628 bytes, got 16192
readFully was waiting for 123436 bytes, got 16192
readFully was waiting for 107244 bytes, got 16192
readFully was waiting for 91052 bytes, got 16192
readFully was waiting for 74860 bytes, got 16192
readFully was waiting for 58668 bytes, got 16192
readFully was waiting for 42476 bytes, got 16192
readFully was waiting for 26284 bytes, got 16192
GC_FOR_ALLOC freed 615K, 13% free 13761K/15687K, paused 10ms, total 11ms
** Activity (main) Pause, UserClosed = false **
Ad opening.
Ad opening.
sending message to waiting queue (adi_adopened)
eglSurfaceAttrib not implemented
Displayed sorex.CLAUStrophobia/com.google.android.gms.ads.AdActivity: +108ms


Edit: tried it on a device with google play store installed, same results. (no ads from inmobi)
 
Last edited:

sorex

Expert
Licensed User
Longtime User
Erel,

can you upload that 5.3.1.jar somewhere plz?

I can't find it anywhere on ze mighty net.
 

sorex

Expert
Licensed User
Longtime User
well, I'm not sure that 6.0 or 6.0.1 is working right.

I'm not getting any ads from them on geny or real device.
 

sorex

Expert
Licensed User
Longtime User
thanks! I will give that a try.

I was just testing with the 6.0.1 and that one spits out errors but still goes on with the lower priority admob ad.

B4X:
Instantiating mediation adapter: com.google.ads.mediation.inmobi.InMobiAdapter
Server parameters: {"gwhirl_share_location":"1"}
Could not request interstitial ad from adapter.
java.lang.ClassCastException: android.app.Application cannot be cast to android.app.Activity
    at com.google.ads.mediation.inmobi.InMobiAdapter.requestInterstitialAd(InMobiAdapter.java:253)
    at com.google.android.gms.internal.zzgx.zza(Unknown Source)
    at com.google.android.gms.internal.zzgr$zza.onTransact(Unknown Source)
    at android.os.Binder.transact(Binder.java:361)
    at com.google.android.gms.ads.internal.mediation.client.g.a(:com.google.android.gms.DynamiteModulesA:522)
    at com.google.android.gms.ads.internal.mediation.f.a(:com.google.android.gms.DynamiteModulesA:330)
    at com.google.android.gms.ads.internal.mediation.g.run(:com.google.android.gms.DynamiteModulesA:9041)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)
Could not request ad from mediation adapter.
android.os.RemoteException
    at com.google.android.gms.internal.zzgx.zza(Unknown Source)
    at com.google.android.gms.internal.zzgr$zza.onTransact(Unknown Source)
    at android.os.Binder.transact(Binder.java:361)
    at com.google.android.gms.ads.internal.mediation.client.g.a(:com.google.android.gms.DynamiteModulesA:522)
    at com.google.android.gms.ads.internal.mediation.f.a(:com.google.android.gms.DynamiteModulesA:330)
    at com.google.android.gms.ads.internal.mediation.g.run(:com.google.android.gms.DynamiteModulesA:9041)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)
Trying mediation network:
Instantiating mediation adapter: com.google.ads.mediation.admob.AdMobAdapter
Server parameters: {"gwhirl_share_location":"1","pubid":"ca-app-pub-5449309153938983\/8088442550\/cak=no_cache&cadc=ws&caqid=qW4EWLrSOK7GxgKw3JH4Aw"}
Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
GC_FOR_ALLOC freed 1593K, 19% free 11058K/13564K, paused 2ms, total 2ms
Starting ad request.
 

sorex

Expert
Licensed User
Longtime User
5.3.1 ain't working either altho it spits out another error

B4X:
Instantiating mediation adapter: com.google.ads.mediation.inmobi.InMobiAdapter
Server parameters: {"gwhirl_share_location":"1"}
Could not request interstitial ad from adapter.
java.lang.NumberFormatException: Invalid long: "null"
    at java.lang.Long.invalidLong(Long.java:124)
    at java.lang.Long.parseLong(Long.java:341)
    at java.lang.Long.parseLong(Long.java:318)
    at com.google.ads.mediation.inmobi.InMobiAdapter.requestInterstitialAd(InMobiAdapter.java:252)
    at com.google.android.gms.internal.zzgx.zza(Unknown Source)
    at com.google.android.gms.internal.zzgr$zza.onTransact(Unknown Source)
    at android.os.Binder.transact(Binder.java:361)
    at com.google.android.gms.ads.internal.mediation.client.g.a(:com.google.android.gms.DynamiteModulesA:522)
    at com.google.android.gms.ads.internal.mediation.f.a(:com.google.android.gms.DynamiteModulesA:330)
    at com.google.android.gms.ads.internal.mediation.g.run(:com.google.android.gms.DynamiteModulesA:9041)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)
Could not request ad from mediation adapter.
android.os.RemoteException
    at com.google.android.gms.internal.zzgx.zza(Unknown Source)
    at com.google.android.gms.internal.zzgr$zza.onTransact(Unknown Source)
    at android.os.Binder.transact(Binder.java:361)
    at com.google.android.gms.ads.internal.mediation.client.g.a(:com.google.android.gms.DynamiteModulesA:522)
    at com.google.android.gms.ads.internal.mediation.f.a(:com.google.android.gms.DynamiteModulesA:330)
    at com.google.android.gms.ads.internal.mediation.g.run(:com.google.android.gms.DynamiteModulesA:9041)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)
 

sorex

Expert
Licensed User
Longtime User
with their 6.0.1 adapter I can see that it reads in my app id, placement id etc from admob so we're making progress.

to be continued...
 

sorex

Expert
Licensed User
Longtime User
I have added that aswell and I see those values passing by now in the logs which didn't happen before.

but now it gives a "Context not an Activity. Returning error!" error
 

sorex

Expert
Licensed User
Longtime User
I tried several. this error occurs with the new 6.0.1 one. I will double check this again.

I followed your rewarded ad tutorial but that one returns a no add fill in the log. my own rewarded ads id ain't not active yet.
 

sorex

Expert
Licensed User
Longtime User
alright, now I got a (non rewarded) video ad displayed probably coming from inmobi.

with the 5.3.1 jars
 

sorex

Expert
Licensed User
Longtime User
just got a reply from those people but it's like chinese to me ...

Hi There,

InMobi Android SDK 600 requires Activity type Object to instantiate InMobi Interstitial ad. So when you must be instantiating AdMob InterstitialAd() object pass object of type Activity as parameter, instead of Context type.

Thanks,
Team InMobi
 
Top