Xamarin, Android: Using the AdListener right

流过昼夜 提交于 2019-12-11 06:01:59

问题


I'm trying to use the AdListener in C#. I have an interstitial ad loading when the app is first started, but sometimes my ad gets skipped because it isn't fully loaded yet. I think an Adlistener should do the trick.

Unfortunately, I have NO CLUE on how to implement it. Also, there is no tutorial on how to do it in C# only in Java and I couldn't find a translation for it :(

Add:

    adListener.OnAdLoaded() += (o, e) =>
    {
        mInterstitialAd.Show();
    };

This doesn't work :(

Any help would be awesome!


回答1:


You can create a class which inherits from Android.Gms.Ads.AdListener, then use the instance of this class as the Listener for your mInterstitialAd, for example:

mInterstitialAd.AdListener = new AdListener(this);

AdListener:

private class AdListener : Android.Gms.Ads.AdListener
{
    private MainActivity that;

    public AdListener(MainActivity t)
    {
        that = t;
    }

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

    public override void OnAdClosed()
    {
        that.RequestNewInterstitial();
        that.BeginSecondActivity();
    }
}

You can also checked the official demo for xamarin android ad: AdMobExample Sample.



来源:https://stackoverflow.com/questions/44229061/xamarin-android-using-the-adlistener-right

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!