【发布时间】:2020-03-28 16:56:55
【问题描述】:
我想在按钮点击时展示插页式广告。 问题是它需要按两次按钮才能显示出来。
界面
public interface IAdInterstitial
{
void ShowAd();
}
Android 类
[assembly: Dependency(typeof(AdMobInterstitial))]
namespace CoronavirusTest.Droid
{
class AdMobInterstitial:IAdInterstitial
{
InterstitialAd interstitialAd;
public AdMobInterstitial()
{
interstitialAd = new InterstitialAd(Android.App.Application.Context);
interstitialAd.AdUnitId = "ca-app-pub-2981452032483899/1747111924";
LoadAd();
}
void LoadAd()
{
var requestbuilder = new AdRequest.Builder();
interstitialAd.LoadAd(requestbuilder.Build());
}
public void ShowAd()
{
if (interstitialAd.IsLoaded)
interstitialAd.Show();
LoadAd();
}
}
}
按钮事件
private void Button_Clicked(object sender, EventArgs e)
{
IAdInterstitial adInterstitial = DependencyService.Get<IAdInterstitial>();
adInterstitial.ShowAd();
}
还在清单中添加了一些我在网上找到的代码,我在应用程序部分中需要阅读这些代码
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >
</activity>
【问题讨论】:
标签: c# android xamarin interstitial