xamarin android奖励视频

时间:2017-02-02 10:43:11

标签: android xamarin google-play-services

Hy Eveyone! 我试图制作一个观看广告"按钮赢得一些"生命"使用Xamarin Android。

我认为这是因为ad_unit_id ...我只是创建了一个RewardVideo,我得到了ca-app-pub-XXXX / XXXX,我有源Unity的UnityAds

我有这段代码

IRewardedVideoAd ad;
protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
....
ad = MobileAds.GetRewardedVideoAdInstance(this);
ad.RewardedVideoAdListener = this;
ad.LoadAd("ca-app-pub-9634192908607048/4854564412", new AdRequest.Builder().Build());

Button adBtn = FindViewById<Button>(Resource.Id.buttonAd);
adBtn.Click += AdBtn_Click;
...
}

private void AdBtn_Click(object sender, EventArgs e)
{
    ad.Show();
}

但是,当我点击=&#34;奖励视频未加载时,我总会回复。&#34;

2 个答案:

答案 0 :(得分:0)

也许你应该实现一个adlistener。就这样:

namespace Ads
{
    public static class AdWrapper
    {
        public static InterstitialAd ConstructFullPageAdd(Context con, string UnitID)
        {
            var ad = new InterstitialAd(con);
            ad.AdUnitId = UnitID;
            return ad;
        }
        public static InterstitialAd CustomBuild(this InterstitialAd ad)
        {
            var requestbuilder = new AdRequest.Builder();
            ad.LoadAd(requestbuilder.Build());
            return ad;
        }
    }
}

namespace admobDemo
{
    class adlistener : AdListener
    {
        // Declare the delegate (if using non-generic pattern).
        public delegate void AdLoadedEvent();
        public delegate void AdClosedEvent();
        public delegate void AdOpenedEvent();
        // Declare the event.
        public event AdLoadedEvent AdLoaded;
        public event AdClosedEvent AdClosed;
        public event AdOpenedEvent AdOpened;

        public override void OnAdLoaded()
        {
            if (AdLoaded != null) this.AdLoaded();
            base.OnAdLoaded();
        }
        public override void OnAdClosed()
        {
            if (AdClosed != null) this.AdClosed();
            base.OnAdClosed();
        }
        public override void OnAdOpened()
        {
            if (AdOpened != null) this.AdOpened();
            base.OnAdOpened();
        }
    }
}

答案 1 :(得分:0)

您应该致电ad.isLoaded查看广告是否已满载,然后致电ad.Show()以显示广告。

以下是一个例子:

if(ad.IsLoaded){
    ad.Show();
}else{
  //ad is not fully loaded wait a few second then click again to see ads
}