Xamarin Admob RewardedVideoAd

I try to use AdMob in my Xamarin project. I aim at displaying a rewarded video on my app. I have issues I can't resolve and that I would like to share with you. Here is my environment :

Xamarin v4.0.1.96
Xamarin Android v6.0.1.10
Xamarin.GooglePlayServices.Ads v27.0.0
I always execute the project on a real device. In case the problem comes from the debug environment, I have published the app on the store and I got the same problem as in local.

using System;
using Android.OS;
using Android.Views;
using Android.Gms.Ads;

    public class ReloadCreditActivity : AppCompatActivityBase, IRewardedVideoAdListener
    {
        public IRewardedVideoAd RewardedVideoAd { get; set; }
        public Button DisplayVideoButton { get; set; }

        private static string AD_UNIT_ID = "ca-app-pub-XXXXXXXXXXXXXX25/XXXXXXXX99";
        private bool _isRewardedVideoLoading;
        private static object _lock = new object();
        protected IRewardedVideoAd _rewardedVideoAd;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.ReloadCreditLayout);

            DisplayVideoButton = FindViewById<Button>(Resource.Id.tabCreditFreemieum_DisplayVideo);

            RewardedVideoAd = MobileAds.GetRewardedVideoAdInstance(this);
            RewardedVideoAd.RewardedVideoAdListener = this;
            LoadRewardedVideoAd();

            DisplayVideoButton.Click += (o, e) =>
            {
                ShowRewardedVideo();
            };
        }

        public void LoadRewardedVideoAd()
        {
            lock (_lock)
            {
                if (!_isRewardedVideoLoading && !RewardedVideoAd.IsLoaded)
                {
                    _isRewardedVideoLoading = true;
                    Bundle extras = new Bundle();
                    extras.PutBoolean("_noRefresh", true);
                    var adMobAdapter = new AdMobAdapter();
                    AdRequest adRequest = new AdRequest.Builder()
                        //.AddTestDevice(AdRequest.DeviceIdEmulator)
                        //.AddTestDevice("FE5692B3DAD1B4CE3BE3BDA2FF4B6103")
                        //.AddNetworkExtrasBundle(adMobAdapter.Class, extras)
                        .Build();
                    RewardedVideoAd.UserId = "pub-74XXXXXXXXXXXXXX";
                    RewardedVideoAd.LoadAd(AD_UNIT_ID, adRequest);
                }
            }
        }

        public void ShowRewardedVideo()
        {
            if (RewardedVideoAd.IsLoaded)
            {
                RewardedVideoAd.Show();
            }
        }

        public void OnRewarded(IRewardItem reward)
        {
            Toast.MakeText(this, string.Format("OnRewarded ! currency: {0} amount: {1}", reward.GetType(), reward.Amount), ToastLength.Short).Show();
        }

        public void OnRewardedVideoAdClosed()
        {
            Toast.MakeText(this, "OnRewardedVideoAdClosed", ToastLength.Short).Show();
            LoadRewardedVideoAd();
        }

        public void OnRewardedVideoAdFailedToLoad(int errorCode)
        {
            lock (_lock)
            {
                _isRewardedVideoLoading = false;
            }
            Toast.MakeText(this, "OnRewardedVideoAdFailedToLoad Code error : " + errorCode, ToastLength.Short).Show();
        }

        public void OnRewardedVideoAdLeftApplication()
        {
            Toast.MakeText(this, "OnRewardedVideoAdLeftApplication", ToastLength.Short).Show();
        }

        public void OnRewardedVideoAdLoaded()
        {
            lock (_lock)
            {
                _isRewardedVideoLoading = false;
            }
            Toast.MakeText(this, "OnRewardedVideoAdLoaded", ToastLength.Short).Show();
        }

        public void OnRewardedVideoAdOpened()
        {
            Toast.MakeText(this, "OnRewardedVideoAdOpened", ToastLength.Short).Show();
        }

        public void OnRewardedVideoStarted()
        {
            Toast.MakeText(this, "OnRewardedVideoStarted", ToastLength.Short).Show();
        }
    }

When I navigate on this page, the app always raise the OnRewardedVideoAdFailedToLoad() callback. I used to get the error code 0 but currently I got the error code 3.

I check the error on Android Device Logging

05-10 11:45:31.600 I/Ads     (14764): Starting ad request.
05-10 11:45:31.600 I/Ads     (14764): Use AdRequest.Builder.addTestDevice("FE5692B3DAD1B4CE3BE3BDA2FF4B6103") to get test ads on this device.
    ...
05-10 11:45:31.910 W/Ads     (14764): Could not instantiate mediation adapter: com.jirbo.adcolony.AdColonyAdapter. com.jirbo.adcolony.AdColonyAdapter
05-10 11:45:31.910 W/Ads     (14764): Fail to instantiate adapter com.jirbo.adcolony.AdColonyAdapter
05-10 11:45:31.910 W/Ads     (14764): android.os.RemoteException
05-10 11:45:31.910 W/Ads     (14764):   at com.google.android.gms.internal.zzel.zzag(Unknown Source)
05-10 11:45:31.910 W/Ads     (14764):   at com.google.android.gms.internal.zzel.zzae(Unknown Source)
05-10 11:45:31.910 W/Ads     (14764):   at com.google.android.gms.internal.zzem$zza.onTransact(Unknown Source)
...
05-10 11:45:31.910 W/Ads     (14764): Could not instantiate mediation adapter: com.fuse.mediation.FuseAdapter. com.fuse.mediation.FuseAdapter
05-10 11:45:31.910 W/Ads     (14764): Fail to instantiate adapter com.fuse.mediation.FuseAdapter
05-10 11:45:31.910 W/Ads     (14764): android.os.RemoteException
05-10 11:45:31.910 W/Ads     (14764):   at com.google.android.gms.internal.zzel.zzag(Unknown Source)
05-10 11:45:31.910 W/Ads     (14764):   at com.google.android.gms.internal.zzel.zzae(Unknown Source)
...
05-10 11:45:31.910 W/Ads     (14764): Could not instantiate mediation adapter: com.google.ads.mediation.chartboost.ChartboostAdapter. com.google.ads.mediation.chartboost.ChartboostAdapter
05-10 11:45:31.910 W/Ads     (14764): Fail to instantiate adapter com.google.ads.mediation.chartboost.ChartboostAdapter
05-10 11:45:31.910 W/Ads     (14764): android.os.RemoteException
05-10 11:45:31.910 W/Ads     (14764):   at com.google.android.gms.internal.zzel.zzag(Unknown Source)
05-10 11:45:31.910 W/Ads     (14764):   at com.google.android.gms.internal.zzel.zzae(Unknown Source)
...
05-10 11:45:31.920 W/Ads     (14764): Could not instantiate mediation adapter: com.google.ads.mediation.unity.UnityAdapter. com.google.ads.mediation.unity.UnityAdapter
05-10 11:45:31.920 W/Ads     (14764): Fail to instantiate adapter com.google.ads.mediation.unity.UnityAdapter
05-10 11:45:31.920 W/Ads     (14764): android.os.RemoteException
05-10 11:45:31.920 W/Ads     (14764):   at com.google.android.gms.internal.zzel.zzag(Unknown Source)
05-10 11:45:31.920 W/Ads     (14764):   at com.google.android.gms.internal.zzel.zzae(Unknown Source)
...
05-10 11:45:31.920 W/Ads     (14764): Could not instantiate mediation adapter: com.vungle.mediation.VungleAdapter. com.vungle.mediation.VungleAdapter
05-10 11:45:31.920 W/Ads     (14764): Fail to instantiate adapter com.vungle.mediation.VungleAdapter
05-10 11:45:31.920 W/Ads     (14764): android.os.RemoteException
05-10 11:45:31.920 W/Ads     (14764):   at com.google.android.gms.internal.zzel.zzag(Unknown Source)
05-10 11:45:31.920 W/Ads     (14764):   at com.google.android.gms.internal.zzel.zzae(Unknown Source)
...
05-10 11:45:31.920 W/Ads     (14764): Failed to load ad: 3

I told myself that maybe it is a problem on my admob configuration with the advertiser, so here is my settings:
image

Maybe I did something wrong on the settings of the advertiser so here are my advertiser.

AdColony :
image

Chartboost :
image

Vungle :
image

Please, give me your feedback.
Thanks a lot.

Tagged:

Best Answer

Answers

  • LucCadoretLucCadoret FRMember

    Nobody have a comment ?

  • The issue here is that you don't have any adapters configured for the Ad networks that you have configured for mediation.

    AdMob is attempting to load ads from all of the providers that you have configured (AdColony, Fuse, Chartboost, etc) but without the appropriate adapter registered, it can't load the ad.

    In your code snippet above, you posted above (repeated below), you will essentially need to uncomment the line for "AddNetworkExtrasBundle" and use that to register adapters for your providers.

    AdRequest adRequest = new AdRequest.Builder() //.AddTestDevice(AdRequest.DeviceIdEmulator) //.AddTestDevice("FE5692B3DAD1B4CE3BE3BDA2FF4B6103") //.AddNetworkExtrasBundle(adMobAdapter.Class, extras) .Build();

    Here is the list of ad networks that have adapters for doing mediation through admob:
    https://firebase.google.com/docs/admob/android/mediation-networks

    You will need to take the SDK / adapter for each ad network, generate the c# bindings, and then reference the dll with those bindings in your app. Then just a tip, the syntax is a little different in c# to get the same behavior as .Class in java so your code will look something like this:

    AdRequest adRequest = new AdRequest.Builder() .AddNetworkExtrasBundle(Java.Lang.Class.FromType(typeof(AdMobAdapter)), extras) .Build();

    Unfortunately I have tried to get this working with AdColony specifically and have had trouble generating the bindings correctly, but in general this approach should work for other ad providers, let me know if it works for you!

  • WildSalmonWildSalmon FRMember ✭✭
    edited August 2016

    Hello,

    I am an another person in the same project

    I tried to generate the c# bindings for the SDK adapter with the help of that tutorial :
    https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/binding-a-jar/#creating

    Following these steps :
    - Create a new Java Bindings Library project.
    - Add the .JAR file to the project.
    - Set the appropriate build action for the .JAR file.
    - Choose a target framework that the .JAR supports.
    - Build the Bindings Library.

    For the adapter VungleAdMobAndroid-1.2.0, the output dll contains only the first class

    The original content of the jar file :

    For the SDK vungle-publisher-adaptive-id-3.3.5
    I got a lot of errors

    any idea on what happens ?

  • RaphaelWilmesRaphaelWilmes USMember
    edited February 2017

    I'm trying to do the same thing than you !
    My Vungle Adapter is include and it's working,

    I think the problem is here,
    Bundle extras = new VungleExtrasBuilder()
    .SetUserId("pub-XXXXXXXXX")
    .SetSoundEnabled(false)
    .Build();

                BuildConfig a = new BuildConfig();
                var adMobAdapter = new AdMobAdapter();
                AdRequest adRequest = new AdRequest.Builder()
                             .AddNetworkExtrasBundle(adMobAdapter.Class, extras)
                             .Build();
                ad.LoadAd("ca-app-pub-XXXXXXXXXXXX/XXXXXXXXXX", adRequest);
    

    Can you help me please ?

  • batmacibatmaci DEMember ✭✭✭✭✭

    @RaphaelWilmes said:
    I'm trying to do the same thing than you !
    My Vungle Adapter is include and it's working,

    I think the problem is here,
    Bundle extras = new VungleExtrasBuilder()
    .SetUserId("pub-XXXXXXXXX")
    .SetSoundEnabled(false)
    .Build();

    BuildConfig a = new BuildConfig();
    var adMobAdapter = new AdMobAdapter();
    AdRequest adRequest = new AdRequest.Builder()
    .AddNetworkExtrasBundle(adMobAdapter.Class, extras)
    .Build();
    ad.LoadAd("ca-app-pub-XXXXXXXXXXXX/XXXXXXXXXX", adRequest);

    Can you help me please ?

    Did you find any solution?

Sign In or Register to comment.