private void requestNewInterstitial(int max) {
if (!adIsLoading && mInterstitialAd == null) {
adIsLoading = true;
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(FirstActivity.this, getString(R.string.inter)),
adRequest, new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
mInterstitialAd = interstitialAd;
adIsLoading = false;
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
@Override
public void onAdDismissedFullScreenContent() {
mInterstitialAd = null;
requestNewInterstitial(5);
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
startActivity(intent);
}
@Override
public void onAdFailedToShowFullScreenContent(@NonNull AdError adError) {
mInterstitialAd = null;
}
});
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
mInterstitialAd = null;
adIsLoading = false;
if (maxretry > 0) {
requestNewInterstitial(maxretry - 1);
}
}
});
}
else{
mInterstitialAd = null;
}
}
您可以在 onAdDismissedFullScreenContent() 方法中看到我如何在代码行中再次请求新的插页式广告:
requestNewInterstitial(5);
。它似乎有效,但我想知道这是否完全可以,或者这违反任何 admob 规则或类似的东西?先谢谢你了
是的,可以,但不要在第一个广告之后立即显示第二个广告,而是在另一个操作之后显示它。