У меня проблемы с отображением рекламы в моем приложении для Android в форме xamarin, в iOS все вроде бы работает нормально, но на Android я просто получаю пустой обзор двух скриншотов:
вот мой манифест Android
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="2.0" package="it.HangoverApp.Hangover" android:installLocation="auto" android:versionCode="1">
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />
<application android:label="Hangover.Android" android:name="android.support.multidex.MultiDexApplication">
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
</provider>
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-3926326346203258~3222437594" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyDhDVDVl6Z1vO9CwAL9xx2ypjMw-QhZAHw" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<provider android:authorities="com.facebook.app.FacebookContentProvider614171362072741" android:name="com.facebook.FacebookContentProvider" android:exported="true" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />
<activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/facebook_app_name" />
<activity android:name="com.facebook.CustomTabActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
</application>
</manifest>
Вот код ячейки:
xmlns:cs="clr-namespace:Hangover.GUIPersonalizzata;assembly=Hangover"
<Frame HasShadow="True" CornerRadius="15" IsVisible = "{Binding shouldDisplayAd}"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HeightRequest = "255"
Margin="5,3,5,1" BackgroundColor="White" Padding="0" IsClippedToBounds="True">
<cs:AdMobView Size="MediumRectangle" VerticalOptions="EndAndExpand"/>
</Frame>
Вот AdMobView:
using System;
using Xamarin.Forms;
namespace Hangover.GUIPersonalizzata
{
///Custom renderer per la pubblicità
public class AdMobView : View
{
public enum Sizes { Standardbanner, LargeBanner, MediumRectangle, FullBanner, Leaderboard, SmartBannerPortrait }
public Sizes Size { get; set; }
public AdMobView()
{
this.BackgroundColor = Color.Black;
}
}
}
А вот пользовательский рендерер:
using Android.Content;
using Android.Gms.Ads;
using Hangover.Droid.CustomRenderer;
using Hangover.GUIPersonalizzata;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobViewRenderer))]
namespace Hangover.Droid.CustomRenderer
{
public class AdMobViewRenderer : ViewRenderer
{
Context context;
public AdMobViewRenderer(Context _context) : base(_context)
{
context = _context;
}
protected override void OnElementChanged(ElementChangedEventArgs<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 = App.getBannerId();
var requestbuilder = new AdRequest.Builder();
adView.LoadAd(requestbuilder.Build());
SetNativeControl(adView);
}
}
}
}
Здесь идентификаторы:
public static String getBannerId()
{
if (TESTMODE)
return "ca-app-pub-3940256099942544/2934735716";
if (Device.RuntimePlatform == Device.iOS)
return "ca-app-pub-3926326346203258/2224942897";
if (Device.RuntimePlatform == Device.Android)
return "ca-app-pub-3926326346203258/8267251849";
return "";
}
public static String getAppAddId()
{
if (Device.RuntimePlatform == Device.iOS)
return "ca-app-pub-3926326346203258~6439520076";
if (Device.RuntimePlatform == Device.Android)
return "ca-app-pub-3926326346203258~3222437594";
return "";
}
Вот выход журнала изобъявление:
[Ads] Используйте AdRequest.Builder.addTestDevice ("23A6FE4B4656BDF0239595258F8C1876") для получения тестовых объявлений на этом устройстве.[DynamitePackage] Создание экземпляра com.google.android.gms.ads.ChimeraAdManagerCreatorImpl [Ads] Использовать
AdRequest.Builder.addTestDevice("23A6FE4B4656BDF0239595258F8C1876") to get test ads on this device.
[Ads] Not retrying to fetch app settings
[Ads] Ad failed to load : 3
[Ads] Ad failed to load : 3
Даже если приложение находится в режиме выпуска, есть идеи?