AdMob横幅广告未显示且未显示说明

问题描述 投票:0回答:1

我创建了一个应用程序并将其与admob连接。它工作正常一周。然后..它刚刚在Android上停止了?我创建了示例应用程序,我的基础应用程序以1:1的方式实现它,看看它是否与其他东西相关而不仅仅是admob?下面我把我的代码用于我使用的admob。

PCL中的控制器:

public class AdMobView : View
{
    public enum Sizes { Standardbanner, LargeBanner, MediumRectangle, FullBanner, Leaderboard, SmartBannerPortrait }
    public Sizes Size { get; set; }
    public AdMobView()
    {
        this.BackgroundColor = Color.Accent;
    }
}

Android正在竞争

public class AdMobRenderer : ViewRenderer
{
    Context context;

    public AdMobRenderer(Context context) : base(context) { }

    protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
    {
        base.OnElementChanged(e);
        if(e.OldElement == null)
        {
            var adView = new AdView(Context);
            switch ((Element as AdMobView).Size)
            {
                case AdMobView.Sizes.Standardbanner:
                    adView.AdSize = AdSize.Banner;
                    break;
                case AdMobView.Sizes.LargeBanner:
                    adView.AdSize = AdSize.LargeBanner;
                    break;
                case AdMobView.Sizes.MediumRectangle:
                    adView.AdSize = AdSize.MediumRectangle;
                    break;
                case AdMobView.Sizes.FullBanner:
                    adView.AdSize = AdSize.FullBanner;
                    break;
                case AdMobView.Sizes.Leaderboard:
                    adView.AdSize = AdSize.Leaderboard;
                    break;
                case AdMobView.Sizes.SmartBannerPortrait:
                    adView.AdSize = AdSize.SmartBanner;
                    break;
                default:
                    adView.AdSize = AdSize.Banner;
                    break;
            }
            adView.AdUnitId = "ca-app-pub-3940256099942544/6300978111";
            var testDeviceId = Android.Provider.Settings.Secure.GetString(Context.ContentResolver, Android.Provider.Settings.Secure.AndroidId);
            var requestBuilder = new AdRequest.Builder().AddTestDevice("c793762db79ab2c6");
            Console.WriteLine("Android device id is: {0}", testDeviceId);
            adView.LoadAd(requestBuilder.Build());
            SetNativeControl(adView);
        }
    }
}

我的朋友和朋友

 public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;
        var id = "my-app-id-with-~"; 
        MobileAds.Initialize(ApplicationContext, id);
        base.OnCreate(savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        LoadApplication(new App());
    }
}

主页

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:AdMobFixed"
         xmlns:adMob="Ad"
         x:Class="AdMobFixed.MainPage">

<StackLayout>
    <!-- Place new controls here -->
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Label 
            Grid.Row="0"
            Text="Welcome to Xamarin.Forms!" 
       HorizontalOptions="Center"
       VerticalOptions="CenterAndExpand" />

        <local:AdMobView 
                         MinimumWidthRequest="400"
                         MinimumHeightRequest="100"
                         HorizontalOptions="CenterAndExpand"
                         VerticalOptions="EndAndExpand"/>
    </Grid>

</StackLayout>

一周前,我没有使用min请求。不幸的是我用Android操作系统打破了我的手机,所以我无法从我的电脑上测试它。下面我附上了我的输出:

02-23 17:14:47.015 D / DynamitePackage(19883):实例化com.google.android.gms.ads.ChimeraAdManagerCreatorImpl

02-23 17:14:47.025 I / Ads(19883):此请求是从测试设备发送的。

02-23 17:14:47.096 I / DynamiteModule(19883):考虑本地模块com.google.android.gms.ads.dynamite:0和远程模块com.google.android.gms.ads.dynamite:11140

02-23 17:14:47.097 I / DynamiteModule(19883):com.google.android.gms.ads.dynamite的选定远程版本,版本> = 11140

Android Manifest还更新了Internet权限和网络状态。我还在aplication标签之间添加了活动标签。

我正在使用nuget Ads lite形式google,我在谷歌的完整play.ads上测试了它。

对于任何帮助,我会非常高兴。先感谢您 ! :)

c# android xamarin xamarin.android admob
1个回答
0
投票

尝试添加此代码:MobileAds.Initialize(ApplicationContext,id);在下面的行上:base.OnCreate(savedInstanceState);

© www.soinside.com 2019 - 2024. All rights reserved.