xamarin RewardedVideo如何替换'this'

xamarin RewardedVideo how to replace 'this'

enter image description here

enter image description here

我已尝试为我的应用复制 https://forums.xamarin.com/discussion/66452/xamarin-admob-rewardedvideoad,但我无法添加奖励视频 AddListener 我们将不胜感激

您的 class 似乎派生自 class 或 AdsGoogle.Droid 命名空间中的接口,而您链接到的示例使用的是 class 或接口在 Android.GMS 命名空间中。这表明您正在尝试使用一些其他产品的教程来与 Google 广告集成?您得到的错误表明编译器不知道如何在 class 的 AdsGoogle.Droid 版本(您的 class)和 Android.GMS 版本的 class(它期望的 class 类型)。

为了把问题说清楚,你可以有两个同名的classes,只要它们在不同的命名空间。页面顶部的 using 语句用于告诉编译器要使用哪个版本的 class。如果它属于其中任何一个,则必须声明完整的命名空间和 class 名称,例如 System.IO.FileMyNamespace.File 而不仅仅是 File.

要解决该问题,请删除行 using AdsGoogle.Droid; 这导致的任何错误都将来自与您正在使用的教程无关的代码部分 - 本教程不会使用该命名空间中的任何内容。

using Android.Gms.Ads;
using Android.Gms.Ads.Reward;
using Xamarin.Forms;
using Android.Views;
using AdsGoogle;
using Android.Widget;
using System;
using System.Timers;
using Android.OS;
using Android.Support.V7.App;

[assembly: Dependency(typeof(AdsGoogle.Droid.AdInterstitial_Droid))]
namespace AdsGoogle.Droid
{
    public class AdInterstitial_Droid : AppCompatActivity, IRewardedVideoAdListener, IAdInterstitial
    {
        public IRewardedVideoAd RewardedVideoAd;

        public AdInterstitial_Droid()
        {
            RewardedVideoAd = MobileAds.GetRewardedVideoAdInstance(Android.App.Application.Context);
            RewardedVideoAd.RewardedVideoAdListener = this;
            //RewardedVideoAd.AdUnitId = "ca-app-pub-2667741859949498/7232000911";
            LoadAd();
        }

        void LoadAd()
        {
            var requestbuilder = new AdRequest.Builder();
            RewardedVideoAd.LoadAd("ca-app-pub-2667741859949498/7232000911", requestbuilder.Build());
        }

        public void ShowRewardedVideo()
        {


            if (RewardedVideoAd.IsLoaded)
            {

                RewardedVideoAd.Show();

                //Toast.MakeText(Android.App.Application.Context, MainPage.AdCoins.ToString(), ToastLength.Long).Show();
            }

            LoadAd();
        }
        
        

它适用于上面的代码。 谢谢元素皮特对我的帮助。