![](/img/trans.png)
[英]xamarin forms capture an external application close event in xamarin forms windows 8.1
[英]Ad Close Event For InterstitialAd Xamarin forms
我正在我的應用程序中實現Google插頁式廣告,效果很好,我只想獲取我通過互聯網搜索到的該廣告的廣告關閉事件,但是我沒有得到此廣告的任何廣告關閉事件,這是我的代碼
我的界面
public interface IAdInterstitial
{
void ShowAd();
void LoadInterstitialAd();
}
我的android自定義渲染器
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());
}
}
我如何獲得此廣告的廣告關閉事件,以便我可以在廣告關閉上做一些事情
您可以創建自己的AdListener子類,該子類偵聽OnAdClosed
事件,然后調用您自己的操作:
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();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.