Reputation: 89
i am implemeting google interstitial ads in my app ads are showing nice and good i just want to get the ad close event for this ad i searched through internet but i did not get any ad close event for this ad here is my code
my interface
public interface IAdInterstitial
{
void ShowAd();
void LoadInterstitialAd();
}
my android custom renderer
public class AdInterstitial_Droid : IAdInterstitial
{
InterstitialAd interstitialAd;
public AdInterstitial_Droid()
{
interstitialAd = new InterstitialAd(Android.App.Application.Context);
// TODO: change this id to your admob id
interstitialAd.AdUnitId = "ca-app-pub-3940256099942544/1033173712";
LoadAd();
}
public void LoadAd()
{
var requestbuilder = new AdRequest.Builder();
interstitialAd.LoadAd(requestbuilder.Build());
}
public void ShowAd()
{
if (interstitialAd.IsLoaded)
interstitialAd.Show();
LoadAd();
}
public void LoadInterstitialAd()
{
var requestbuilder = new AdRequest.Builder();
interstitialAd.LoadAd(requestbuilder.Build());
}
}
how i can get the ad close event for this ad so that i can do some stuff on ad close
Upvotes: 1
Views: 378
Reputation: 74174
You can create your own AdListener subclass that listens for the OnAdClosed
event and than invokes your own action:
public AdInterstitial_Droid()
{
interstitialAd = new InterstitialAd(Android.App.Application.Context);
interstitialAd.AdListener = new MyAdListener(() =>
{
// Ad closing, do whatever you need to do
});
// TODO: change this id to your admob id
interstitialAd.AdUnitId = "xxxxx";
LoadAd();
}
public class MyAdListener : AdListener
{
Action OnCloseAction;
public MyAdListener(Action OnCloseAction)
{
this.OnCloseAction = OnCloseAction;
}
public override void OnAdClosed()
{
OnCloseAction?.Invoke();
base.OnAdClosed();
}
}
Upvotes: 1