If someone could help me (or anyone) on the subject of integrating Ads (maybe AdMob) in Monogame 3.3, it would be great How to do it in the most current version? Any tutorial? Iāve never done it before, so any help is apprieciated.
I did a rough implementation of AdMob in Monogame in Doom & Destiny Free for Android and IOS.
You essentially have to use the Xamarin AdMob component and follow the samples in the componentā¦
If you have some specific question iāll be glad to help!
Download the Google Play Services component from the Xamarin Components store. The code below is a test app I put together using the standard Xamarin Studio new Android app template - modify accordingly:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Gms.Ads;
namespace GoogleServicesTest
{
[Activity (Label = āGoogleServicesTestā, MainLauncher = true, Icon = ā@drawable/iconā)]
public class MainActivity : Activity
{
int count = 1;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button> (Resource.Id.myButton);
button.Click += delegate {
button.Text = string.Format ("{0} clicks!", count++);
};
// Begin Admob integration
var ad = new AdView(this);
ad.AdSize = AdSize.SmartBanner;
ad.AdUnitId = "[YOUR ADMOB ID HERE]";
var requestbuilder = new AdRequest.Builder();
ad.LoadAd(requestbuilder.Build());
var layout = FindViewById<LinearLayout>(Resource.Id.mainLayout);
layout.AddView(ad);
}
}
Thanks for the sample! However I did not manage to compile it. After getting Xamarin Google Play Component (succesfully added it to fresh andro project) I could not compile it. Errors were something like resource not found declared in values.xml. After that schemas not declaredā¦
EDIT 2:
Schema and compile errors solved by adding 1G to java max heap size. Unfortunately, there are still lots of warnings on compile. But I believe itās Xamarin component fault.
EDIT 1:
Okay Iāve successfuly managed to run admob. However I ran into one main problem - ad is not showing up on startup (after first request build). Itās there because when I pause my app and then resume it - ad comes visible. Ad also becomes visible adter scheduled refreshā¦
@mpeg88 - awesome stuff, glad to hear you got those errors resolved! And apologies for neglecting to mention that my sample was for banner ads, not interstitialsā¦
You also found a solution to a problem that has been bugging me for a while - the first of my banner ads to load was not being displayed, so there was about a minuteās delay between the game opening and an ad actually showing. But that little trick with the AdListener calling RequestLayout on load seems to have done the trick, so thanks a lot!
I love you ! I got serveral errors too with values.xml and other things ā¦ It was horrible ! But adding 1G to java max heap size resolve every things ! You re my hero ! Love you <3