Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Admob Rewarded Video support for Xamarin

$
0
0

Hi!

I've been struggling for some time to implement rewarded video ads in my app, using Admob network. I've managed to display a video ad on android, but I simply can't have the listener to trigger the OnRewarded event. This is how I implement it:

`

public class AdMobInter : IAdmobInter
{
    InterstitialAd _ad;

    public void Show(string adUnit)
    {
        var context = Android.App.Application.Context;
        _ad = new InterstitialAd(context);
        _ad.AdUnitId = adUnit;

        var intlistener = new InterstitialAdListener(_ad);
        intlistener.OnAdLoaded();
        _ad.AdListener = intlistener;

        var requestbuilder = new AdRequest.Builder();

        _ad.LoadAd(requestbuilder.Build());
    }
}

public class InterstitialAdListener : AdListener, IRewardedVideoAdListener
{
    readonly InterstitialAd _ad;

    public InterstitialAdListener(InterstitialAd ad)
    {
        _ad = ad;
        _ad.RewardedVideoAdLoaded += (o, e) => OnRewardedVideoAdLoaded();
        _ad.RewardedVideoAdClosed += (o, e) => OnRewardedVideoAdClosed();
    }

    public override void OnAdLoaded()
    {
        base.OnAdLoaded();

        if (_ad.IsLoaded)
        {
            _ad.Show();
    //THIS EVENT WORKS//
            //MY CODE HERE//

        }
    }

    public override void OnAdFailedToLoad(int errorCode)
    {
        base.OnAdFailedToLoad(errorCode);
//THIS EVENT WORKS//
        //MY CODE HERE//
    }

    public void OnRewarded(IRewardItem reward)
    {
     //THIS EVENT WON'T TRIGGER//
    //MY CODE HERE//
    }

    public void OnRewardedVideoAdClosed()
    {
        //THIS EVENT WORKS//
    //MY CODE HERE//
    }

    public void OnRewardedVideoAdFailedToLoad(int errorCode)
    {

    }

    public void OnRewardedVideoAdLeftApplication()
    {

    }

    public void OnRewardedVideoAdLoaded()
    {
        //THIS EVENT WORKS//
    //MY CODE HERE//
    }

    public void OnRewardedVideoAdOpened()
    {

    }

    public void OnRewardedVideoStarted()
    {

    }
}

`

I've read in some places that the Admob network only support native frameworks, and Xamarin is still not supported. Is this really the case? I'm thinking in just leaving it like that and the user will get an internal reward regardless of watching the whole video or not. It's not ideal for me, but what can I do? I'm using a PCL project, currently working on the Android.

How do you guys deal with that in your apps? Any hint is appreciated!


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>