With both test and my ids ads show fine in ios. In android they do not with either. Tried with xamarin.firebase.ads and xamarin.googleplayservies.ads and neither works and throws no errors. How do I debug?
Code:
shared AdBanner.cs
using System;
using Xamarin.Forms;
namespace AdMob.CustomRenders
{
public class AdBanner : View
{
public enum Sizes
{
Standardbanner, LargeBanner, MediumRectangle, FullBanner, Leaderboard, SmartBannerPortrait
}
public Sizes Size
{
get; set;
}
public AdBanner()
{
this.BackgroundColor = Color.Accent;
}
}
}
snippet of xaml
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage.Content>
Android manifest (XXS IN ID TO HIDE REAL ID
<?xml version="1.0" encoding="utf-8"?>
<application android:label="Scent Work Log" android:icon="@drawable/ic_launcher_round">
<provider android:name="androidx.core.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-87XXXX5634776~7430XXX315"/>
<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>
AdBanner_droid.cs
using System;
using AdMob;
using Android.Gms.Ads;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using AdMob.CustomRenders;
using AdMob.Droid.CustomRenders;
using Android.Content;
[assembly: ExportRenderer(typeof(AdBanner), typeof(AdBanner_Droid))]
namespace AdMob.Droid.CustomRenders
{
public class AdBanner_Droid : ViewRenderer
{
Context context;
public AdBanner_Droid(Context _context) : base(_context)
{
context = _context;
}
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
var adView = new AdView(Context);
switch ((Element as AdBanner).Size)
{
case AdBanner.Sizes.Standardbanner:
adView.AdSize = AdSize.Banner;
break;
case AdBanner.Sizes.LargeBanner:
adView.AdSize = AdSize.LargeBanner;
break;
case AdBanner.Sizes.MediumRectangle:
adView.AdSize = AdSize.MediumRectangle;
break;
case AdBanner.Sizes.FullBanner:
adView.AdSize = AdSize.FullBanner;
break;
case AdBanner.Sizes.Leaderboard:
adView.AdSize = AdSize.Leaderboard;
break;
case AdBanner.Sizes.SmartBannerPortrait:
adView.AdSize = AdSize.SmartBanner;
break;
default:
adView.AdSize = AdSize.Banner;
break;
}
// TODO: change this id to your admob id
adView.AdUnitId = "ca-app-pub-8767021289934776/6619715915";
var requestbuilder = new AdRequest.Builder();
adView.LoadAd(requestbuilder.Build());
SetNativeControl(adView);
}
}
}
}
snippet of main activity
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.SetTheme(Resource.Style.MainTheme);
MobileAds.Initialize(ApplicationContext, "ca-app-pub-8767021289934776~7430520115");
UserDialogs.Init(this);